shayne97
shayne97
2017-10-19 08:30

MYSQL : 1583 'IFNULL'

100
  • mysql
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条回答

为你推荐

换一换