我在做什么。
我有一个删除行的过程。
我var_SelectedIds
越来越,
分离UUID()
然后
SET @var_SQLStr = '';
SET @var_SQLStr = CONCAT(@var_SQLStr ,'Delete ');
SET @var_SQLStr = CONCAT(@var_SQLStr ,'FROM DemoTable');
SET @var_SQLStr = CONCAT(@var_SQLStr ,'WHERE DemoTableId IN (''',Replace(var_SelectedIds,',',''','''),'''); ');
-- SELECT @var_SQLStr;
PREPARE stmt FROM @var_SQLStr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
我已经尝试过的。
// This is throwing SQL Syntax ERROR.
SET @var_SQLStr = '';
SET @var_SQLStr = CONCAT(@var_SQLStr ,'Delete ');
SET @var_SQLStr = CONCAT(@var_SQLStr ,'FROM DemoTable');
SET @var_SQLStr = CONCAT(@var_SQLStr ,'WHERE DemoTableId IN (''',Replace(var_SelectedIds,',',''','''),'''); ');
SET @var_SQLStr = CONCAT(@var_SQLStr ,' SELECT ROWS_COUNT() INTO @var_AffectedRows; ');
-- SELECT @var_SQLStr;
PREPARE stmt FROM @var_SQLStr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
文本必须代表单个语句,而不是多个语句。
我也试过
START TRANSACTION;
-- Other statements here
SET @var_SQLStr = '';
SET @var_SQLStr = CONCAT(@var_SQLStr ,'Delete ');
SET @var_SQLStr = CONCAT(@var_SQLStr ,'FROM DemoTable');
SET @var_SQLStr = CONCAT(@var_SQLStr ,'WHERE DemoTableId IN (''',Replace(var_SelectedIds,',',''','''),'''); ');
-- SELECT @var_SQLStr;
PREPARE stmt FROM @var_SQLStr;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT ROW_COUNT() INTO @var_AffectedRows
COMMIT;
SELECT @var_AffectedRows AS NoOfRowsDeleted; // 0 output
我无法了解如何删除行。