首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

MYSQL 存储过程内用存储过程的参数作表名查找解决方法

2012-02-17 
MYSQL 存储过程内用存储过程的参数作表名查找createproceduretest(intablenamevarchar(10))begindeclarete

MYSQL 存储过程内用存储过程的参数作表名查找
create   procedure   test(in   tablename   varchar(10))
begin
declare     temp   cursor     for     select   *   from   tablename   ;
open   temp;
....
end   temp;

end

[解决办法]
set sql_stat=concat( 'declare temp cursor for select from ',tablename);

SET @RUNSQL = sql_stat;
PREPARE A FROM @RUNSQL;
EXECUTE A;
DEALLOCATE PREPARE A;


象我这样写,给分吧

[解决办法]
create procedure pg_proc()
begin
SET @test=CONCAT('select * from',?);
PREPARE tt from @test;
set @tableName=tablename;
execute tt using @tableName;
end;

在mysql5.2使用正常,mysql5.0.2使用不正常,版本问题.

热点排行