我想用特定的time_stamp和pro_id
调用动态过程。
在第一步中,我想知道表中是否存在特定的pro_id
。 Concat
声明中有什么不对吗?我没有得到所需的OUT
值
DELIMITER ;;
CREATE PROCEDURE 'ADDCONSENSUS'(IN time_stamp int(10), IN pro_id INT(10), OUT cnt INT(11))
BEGIN
SET @sql1 = CONCAT('SELECT COUNT(pid) INTO @cnt FROM ',time_stamp,' WHERE pid = ,pro_id);
PREPARE stmt from @sql1;
EXECUTE stmt;
END
答案 0 :(得分:0)
您可以尝试以下操作:
DELIMITER $$
DROP PROCEDURE IF EXISTS `ADDCONSENSUS`$$
CREATE PROCEDURE `ADDCONSENSUS`(
IN `time_stamp` INT,
IN `pro_id` INT,
OUT `cnt` INT)
BEGIN
SET @sql1 := CONCAT('
SELECT COUNT(`pid`) INTO @`cnt`
FROM `', CAST(`time_stamp` AS CHAR), '`
WHERE `pid` = ', CAST(`pro_id` AS CHAR));
PREPARE stmt FROM @sql1;
EXECUTE stmt;
SET `cnt` := @`cnt`;
DEALLOCATE PREPARE stmt;
END$$
DELIMITER ;
CALL `ADDCONSENSUS`(1395395302, 3, @`_count`);