我正在尝试创建并使用此过程:
delimiter //
CREATE PROCEDURE doiterate(p1 INT)
BEGIN
DECLARE str VARCHAR(5000);
label1: LOOP
SET @query = 'SELECT * FROM ';
IF p1 > 0 THEN
SET @query = CONCAT(@query, ' wp_', pl, '_options,');
ITERATE label1;
END IF;
LEAVE label1;
END LOOP label1;
SET @query = substring(@query,1,length(@query)-1);
SET @query = CONCAT(@query, ' WHERE option_name = \'template\'OR option_name = \'stylesheet\' OR option_name = \'current_theme\'');
PREPARE stmt FROM @query;
EXECUTE stmt;
END//
当我执行它时,我收到了这条消息:
“字段列表”中的未知列'pl'
任何人都可以指出我做错了吗?
答案 0 :(得分:1)
您的代码中有拼写错误:
SET @query = CONCAT(@query, ' wp_', pl, '_options,');
应该是
SET @query = CONCAT(@query, ' wp_', p1, '_options,');
您使用了“PL”(强调大写)代替“p1”;