MYSQL : 1583 'IFNULL'
1583 - Incorrect parameters in the call to native function 'IFNULL'


DECLARE p_substoreid NVARCHAR(100);
DECLARE p_Fname NVARCHAR(100);
DECLARE p_name NVARCHAR(100);

DECLARE no_more_departments INTEGER DEFAULT 0;  

DECLARE Cursor__bigclass CURSOR FOR SELECT `name` FROM Tempdb__bigclass;    

DECLARE Cursor_thedate CURSOR FOR SELECT substoreid,Fname FROM Tempdb__thedate; 

DECLARE CONTINUE HANDLER FOR NOT FOUND
         SET no_more_departments=1;         
DROP TEMPORARY TABLE IF EXISTS Tempdb__hdnames;
DROP TEMPORARY TABLE IF EXISTS Tempdb__receive_report;
DROP TEMPORARY TABLE IF EXISTS Tempdb__thedate;
DROP TEMPORARY TABLE IF EXISTS Tempdb__tab;
DROP TEMPORARY TABLE IF EXISTS Tempdb__bigclass;

SET @v_sql= CONCAT('Create TEMPORARY Table Tempdb__hdnames(select substoreid as `name` from hotelid where substoreid in (', p_FdName,'))');
PREPARE stmt FROM @v_sql; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt;


SET @v_sql= CONCAT('Create TEMPORARY Table Tempdb__bigclass(SELECT id as `name` FROM home_class  GROUP BY `id` )');
PREPARE stmt FROM @v_sql; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt;

CREATE TEMPORARY TABLE Tempdb__receive_report(
    SELECT A.* , B.bname  AS Fname  FROM receive_report A
      LEFT JOIN  hotelid B ON A.substoreid=B.substoreid
     WHERE  A.the_date BETWEEN  p_StarDate  AND p_EndDate
      AND A.substoreid IN (SELECT `name` FROM Tempdb__hdnames)
       AND (A.name='房型统计' OR A.name='房类'));

CREATE TEMPORARY TABLE  Tempdb__thedate (SELECT substoreid,Fname FROM Tempdb__receive_report  GROUP BY substoreid,  Fname);



SET @tab_sql='Create TEMPORARY Table Tempdb__tab(rq NVARCHAR(100),Fname NVARCHAR(100),hjzfs FLOAT,hjczs FLOAT,hjzj FLOAT';
SET @where_sql = '';
SET @column_sql = '';
SET @select_column_sql = '';
OPEN Cursor__bigclass; 
REPEAT        
    FETCH Cursor__bigclass INTO p_name;   
    BEGIN
       IF NOT no_more_departments THEN
        SET @tab_sql= CONCAT(@tab_sql,',`C', p_name,'Czfs` FLOAT',',`C', p_name,'Cczs` FLOAT',',`C', p_name,'Czj` FLOAT'); 
        SET @column_sql = CONCAT(@column_sql,',`C', p_name,'Czfs`',',`C', p_name,'Cczs`',',`C', p_name,'Czj`');                 
        SET @where_sql = CONCAT(@where_sql,',IFNULL(SUM(CASE WHEN (id =''',p_name,''' and `name`=''房型统计'') THEN day_rooms END) ,0)'
        ,',IFNULL(SUM(CASE WHEN (id =''',p_name,''' and `name`=''房类'') THEN day_rooms END) ,0)'
        ,',IFNULL(SUM(CASE WHEN (id =''',p_name,''' and `name`=''房类'') THEN day_money END) ,0)');

        SET @select_column_sql = CONCAT(@select_column_sql,' 
        , IFNULL(C',p_name,'Czfs,0) as C',p_name,'Czfs, IFNULL(C',p_name,'Cczs,0) as C',p_name,'Cczs, IFNULL(C',p_name,'Czj,0) as C',p_name,'Czj
        ,CASE IFNULL(C',p_name,'Czfs,0) WHEN 0 THEN 0 ELSE IFNULL(C',p_name,'Cczs,0)/C',p_name,'Czfs END AS C',p_name,'Cczl
        ,CASE IFNULL(C',p_name,'Cczs,0) WHEN 0 THEN 0 ELSE IFNULL(C',p_name,'Czj,0)/C',p_name,'Cczs END AS C',p_name,'Cpjfj');

       END IF;

    END;



    UNTIL no_more_departments  END REPEAT;   
    CLOSE Cursor__bigclass;                    

    SET @tab_sql= CONCAT(@tab_sql,');');


PREPARE stmt FROM @tab_sql; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt;

SET no_more_departments = 0;


OPEN Cursor_thedate; 
REPEAT        
FETCH Cursor_thedate INTO  p_substoreid,p_Fname;     
  BEGIN 
    IF NOT no_more_departments THEN

        SET @execute_sql= CONCAT('INSERT INTO Tempdb__tab(rq,Fname,hjzfs,hjczs,hjzj'                
        ,@column_sql,') SELECT ''',IFNULL(p_substoreid,''),''',''',IFNULL(p_Fname,''),'''
        ,IFNULL(SUM(CASE WHEN (id =''总房数'' and `name`=''房型统计'') THEN day_rooms END),0)
        ,IFNULL(SUM(CASE WHEN (id =''合计'' and `name`=''房类'') THEN day_rooms END),0)
        ,IFNULL(SUM(CASE WHEN (id =''合计'' and `name`=''房类'') THEN day_money END),0)'
        ,@where_sql,' 
         FROM Tempdb__receive_report WHERE substoreid=',p_substoreid,';');
        PREPARE stmt FROM @execute_sql; 
        EXECUTE stmt; 
        DEALLOCATE PREPARE stmt; 

    END IF; 
END;

UNTIL no_more_departments  END REPEAT;   
    CLOSE Cursor_thedate;                    

SET @execute_sql= CONCAT('SELECT rq,Fname,hjzfs,hjczs,hjzj
         ,CASE IFNULL(hjzfs,0) WHEN 0 THEN 0 ELSE IFNULL(hjczs,0)/hjzfs END AS hjczl
         ,CASE IFNULL(hjczs,0) WHEN 0 THEN 0 ELSE IFNULL(hjzj,0)/hjczs END AS hjpjfj'
        ,@select_column_sql,' FROM Tempdb__tab ORDER BY rq;');

PREPARE stmt FROM @execute_sql; 
EXECUTE stmt; 
DEALLOCATE PREPARE stmt; 
END


    存储过程报错,求助,急急急!!!

2个回答

Incorrect parameters in the call to native function 'IFNULL'
你检查用这个函数的参数,它说这个参数不正确,具体程序里,你看看这个参数值是不是有问题,不是字符串或者null

u011126065
jasondyoung 回复shayne97: 具体程序里执行这里的结果,跟单独运行不一定一样。我看有很多地方用到ifnull,你先只用一个,而且语句写的简单点。在程序里验证
2 年多之前 回复
shayne97
shayne97 IFNULL 的作用是判断是否为空,然后替换吧,所以检查了很久没有找到原因来求助。然后,在另外一个库里面执行不会报错,想知道大概是什么位置的原因就好处理了。
2 年多之前 回复

错误信息明显指出 :是你在调用的时候报错了,错误的调用了IFNULL函数。
结合参数看下存储过程中,所有用到IFNULL函数的地方,一一排查。

shayne97
shayne97 IFNULL 的作用是判断是否为空,然后替换吧,所以检查了很久没有找到原因来求助。然后,在另外一个库里面执行不会报错,想知道大概是什么位置的原因就好处理了。
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐