存储过程字符串拼接mysql_mysql存储过程求⼤神(拼接字符
串)
BEGINdeclaretable_nameVARCHAR(100);declarestopFlagint;declaresql1VARCHAR(1000);declarecursor_namecursorforselect
BEGIN
declare table_name VARCHAR (100);
declare stopFlag int;
declare sql1 VARCHAR (1000);
declare cursor_name cursor
for select TABLE_NAME from information_schema.KEY_COLUMN_USAGE where TABLE_NAME like 'test_2014%';
declare CONTINUE HANDLER FOR NOT FOUND set stopFlag=1;
set @sql1='create or replace view test as select id,name from ';
open cursor_name;
REPEAT
FETCH cursor_name INTO table_name;
begin
set @sql1=CONCAT(@sql1,table_name);
select @sql1;
PREPARE step FROM @sql1;
EXECUTE step;
end;
FETCH cursor_name INTO table_name;
UNTIL stopFlag = 1
END REPEAT;
close cursor_name;
END
如上存储过程,实现的是数据库中有多个表名为test_201409、等表格,这些表格结构字段都⼀样,现在⽤游标把它们查
询出来后,根据这些表创建视图,有⼀个拼接的过程不会 求⼤神帮忙看下
拼接后的Sql:
select id,namemysql视图和存储过程
from test_201409
union all select id,name from
先给80分 好了再给80 求⼤神
已经解决!
展开

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。