日期:2014-05-16  浏览次数:20636 次

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使用不正常,版本问题.