SET @str='key1:1;key2:4;key3:22';
SET @str='SELECT '+''''+ REPLACE(@str,';','''  union all select ''')+'''';
PRINT @str;
declare cur5 Cursor for SELECT 'key1:1'  union all select 'key2:4'  union all select 'key3:22'
open cur5
这样的代码是可以得到我要的结果 输出结果为
SELECT 'key1:1'  union all select 'key2:4'  union all select 'key3:22'
key1:1
key2:4
key3:22但是如果我初始化的时候用变量
SET @str='key1:1;key2:4;key3:22';
SET @str='SELECT '+''''+ REPLACE(@str,';','''  union all select ''')+'''';
PRINT @str;
declare cur5 Cursor for @str为什么这样会提示@