Creating temporary tables in MySQL Stored Procedure

前端 未结 2 409
感动是毒
感动是毒 2020-12-28 14:34

The following procedure gives me an error when I invoke it using the CALL statement:


CREATE DEFINER=`user`@`localhost` PROCEDURE `emp_performance`(id VARCHA         


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-28 14:45

    By default MySQL config variable sql_notes is set to 1.

    That means that DROP TEMPORARY TABLE IF EXISTS performance; increments warning_count by one and you get a warning when a stored procedure finishes.

    You can set sql_notes variable to 0 in my.cnf or rewrite stored procedure like that:

    CREATE DEFINER=`user`@`localhost` PROCEDURE `emp_performance`(id VARCHAR(10))
    BEGIN
    SET @@session.sql_notes = 0;
    DROP TEMPORARY TABLE IF EXISTS performance;
    CREATE TEMPORARY TABLE performance AS  
        SELECT time_in, time_out, day FROM attendance WHERE employee_id = id;
    SET @@session.sql_notes = 1;
    END
    

提交回复
热议问题