sql伪代码:select * from (select dbname from dbuser where name='aaa').test
1.在数据库创建存储过程,用于实现根据不用户查询不同的数据源;
/*创建存储过程,设置入参 para_user,用于接收用户信息参数*/
create PROCEDURE proc_dynamic(in para_user nvarchar(20))
begin
declare stmt nvarchar(200);
declare sqlstr nvarchar(200);
declare dbname nvarchar(20);
/*获取该用户的数据源名称*/
select dbinfo into dbname from user where name = para_user;
set sqlstr=concat("select * from ",dbname,".test");
set @sql=sqlstr;
/*prepare预处理*/
prepare stmt from @sql;
EXECUTE stmt;
/*释放预处理*/
DEALLOCATE PREPARE stmt;
end;