写一个存储过程
create procedure test (IN test char(20))
READ SQL DATA
BEGIN
select * from test.table;
end;
报错,说没有test.table,我想引用的是参数的数据库名称,但是报错,不知道mysql有没有这样的写法,识别参数 test.table test是参数,是数据库名,table是实际的表名(有这个表table)

解决方案 »

  1.   

    set @asql=concat('select * from ',test,'.table;');
    prepare stml from @asql;
    execute stml;
      

  2.   

    数据库名 表名  字段名  当参数输入进去的时候  需要拼接动态sql
      

  3.   

    当字段名、表名、数据库名作为参数传入,要拼接动态sql
    set @sql=concat('select * from  test.table1;');
    prepare stml from @sql;
    execute stml;
      

  4.   

    数据库名无法使用变量,只能进行拼接字符串生成SQL语句,然后通过 prepare / execute 来执行。