你的位置:
问答吧
-> MySQL
-> 问题详情
mysql动态SQL问题?
mysql中能否把动态SQL语句执行后的结果导入到一临时表中?
如下:
mysql> set @s = concat( 'select ', replace('101,102,106,109',',',' union all seect '));
mysql> prepare stmt from @s ;
mysql> execute stmt;
# 想把最后一句招行后的结果导入到临时表中,在SQL server中可以使用insert into #t exec sp_execute @s
#mysql中不知道具体解决办法
作者: pzlydg
发布时间: 2008-03-04
QUOTE:原帖由 pzlydg 于 2008-3-4 09:46 发表
mysql中能否把动态SQL语句执行后的结果导入到一临时表中?
如下:
mysql> set @s = concat( 'select ', replace('101,102,106,109',',',' union all seect '));
mysql> prepare stmt from @s ;
mysql> execute stmt;
# 想把最后一句招行后的结果导入到临时表中,在SQL server中可以使用insert into #t exec sp_execute @s
#mysql中不知道具体解决办法
create temporary table t
select * from ....
但是把动态生成的语句数据写到表中,好象存在问题.....但是你可以把创建临时表的语句一起放到动态语句中执行
set @s = concat( 'create temporary table t ','select ', replace('','101,102,106,109',',',' union all seect '));
直接: create temporary table t execute stmt; 是不行的
[ 本帖最后由 jinguanding 于 2008-3-4 10:36 编辑 ]
作者: jinguanding
发布时间: 2008-03-04
set @s = concat('create temporary table t ','select ', ' 101,102,106,109');
prepare stmt from @s ;
execute stmt;
我试 过了:
(0 row(s)affected)
(0 ms taken)
(0 row(s)affected)
(0 ms taken)
(1 row(s)affected)
(0 ms taken)
作者: jinguanding
发布时间: 2008-03-04
create temporary table tmp select ...
作者: yueliangdao0608
发布时间: 2008-03-04
多谢两位楼主的热心
还是对mysql语法不熟(create table ....select * from 这种语法是不错),往后还要向两位多请教了
作者: pzlydg
发布时间: 2008-03-04