【发布时间】:2012-12-07 07:11:24
【问题描述】:
我想创建一个存储过程,它接受 IN 参数中的所有值作为单个字符串。
DELETE FROM object
WHERE Type NOT IN
('ListGrid',
'TextField',
'SpinBox',
'MenuButton',
'ListGrid',
'RadioButton',
'DropDown',
'PopUp',
'Element',
'Checkbox',
'TreeDropDown',
'TblColumn',
'Button',
'Link',
'Filter',
'TblRow',
'GridRow',
'Popup')
这是我尝试过的一个示例,但它不起作用。
DELIMITER //
CREATE PROCEDURE deleteObjectTypes(IN p_type VARCHAR(255))
BEGIN
SET @query = CONCAT ('DELETE FROM object WHERE Type NOT IN (',p_type,')');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END //
DELIMITER ;
我收到以下错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''List)' at line 1
运行此查询时:
CALL deleteObjectTypes("'ListGrid1','TextField1','SpinBox1','MenuButton1','ListGrid2','TextField2','SpinBox2','MenuButton2','ListGrid3','TextField3','SpinBox3','MenuButton3','ListGrid4','TextField4','SpinBox4','MenuButton4','ListGrid5','TextField5','SpinBox5','MenuButton5','ListGrid6','TextField6','SpinBox6','MenuButton6'")
【问题讨论】:
-
您在运行此程序时是否收到错误消息?
-
发布更新,见编辑。
-
该错误与您目前提供的代码的任何部分都不匹配。但看起来你可能有一个额外的
'在那里
标签: mysql sql stored-procedures