开发者

ERROR when send table as parameter in MySQL store procedure

I wrote a store procedure. It executes properly, but when I call the procedure, it shows the error:

Error Code : 1327 Undeclared 开发者_StackOverflow社区variable: Third

Please see my procedure below:

DELIMITER $$
USE `db_test`$$
DROP PROCEDURE IF EXISTS `test_proc`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test_proc`(IN newsInfoTable VARCHAR(100))
BEGIN     
    SET @sql_stam = CONCAT('SELECT news INTO ', @news,' FROM ',newsInfoTable,' WHERE ',CURDATE(),'=?;');      
    PREPARE s1 FROM @sql_stam;     
    SET @where_param = DATE_FORMAT(date_time,'%Y-%m-%d');     
    EXECUTE s1 USING @where_param;    
    SELECT @news;          
 END$$
DELIMITER ;

Calling parameter:

USE db_test;
CALL test_proc('tbl_morning_news');


Change your code into:

DELIMITER $$
USE `db_test`$$
DROP PROCEDURE IF EXISTS `test_proc`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test_proc`(IN newsInfoTable VARCHAR(100))
BEGIN     
    SET @sql_stam = CONCAT( 'SELECT news INTO @news FROM ',newsInfoTable
                           ,' WHERE DATE(`date_time`) = CURDATE()' );      
    PREPARE s1 FROM @sql_stam;         
    SELECT @news;          
 END$$
DELIMITER ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜