显示用户表中存在的多个表

时间:2015-01-02 09:57:59

标签: sql plsql

我们必须显示user_tables中所有表中的数据。我的代码是

DECLARE
name varchar2(50);
s_query varchar2(500);
cursor c_demo is select table_name from    user_tables;
BEGIN
open c_demo;
loop
fetch c_demo into name;
EXIT WHEN c_demo%notfound;
select * into s_query from @name; 
dbms_output.put_line(s_query);
end loop;
close c_demo;
end;

但它显示错误表缺少

1 个答案:

答案 0 :(得分:0)

您可以像这样执行动态SQL:

1.定义var

     sql_stmt  VARCHAR2(200);
  1. 构建查询

     sql_stmt := 'select * from '||name; 
    
  2. Exceute Statement:

    for r in sql_stmt
    loop
    //perfom operation on data
    
    end loop;