栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从all_tables中选择表?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从all_tables中选择表?

大概您当前的查询正在获取

ORA-00904: "CALLE": invalididentifier
,因为子查询没有名为的列
CALLE
。不幸的是,您不能在运行时那样为查询提供表名,而必须诉诸于动态SQL。

这样的事情将遍历所有表,并且对于每个表都会

CALLE
从每个表中获取所有值,然后您就可以遍历这些表。我曾经
DBMS_OUTPUT
显示过它们,假设您是在SQL* Plus或其他可以处理的事情中执行的;但您可能想对他们做其他事情。

set serveroutput ondeclare    -- declare a local collection type we can use for bulk collect; use any table    -- that has the column, or if there isn't a stable one use the actual data    -- type, varchar2(30) or whatever is appropriate    type t_values is table of table.calle%type;    -- declare an instance of that type    l_values t_values;    -- declare a cursor to generate the dynamic SQL; where this is done is a    -- matter of taste (can use 'open x for select ...', then fetch, etc.)    -- If you run the query on its own you'll see the individual selects from    -- all the tables    cursor c1 is        select table_name, 'select calle from ' || owner ||'.'|| table_name as query        from all_tables        where owner = 'FMJ'        and table_name like 'BACKUP_SEMAFORO_GEO%'        order by table_name;begin    -- loop around all the dynamic queries from the cursor    for r1 in c1 loop        -- for each one, execute it as dynamic SQL, with a bulk collect into        -- the collection type created above        execute immediate r1.query bulk collect into l_values;        -- loop around all the elements in the collection, and print each one        for i in 1..l_values.count loop dbms_output.put_line(r1.table_name ||': ' || l_values(i));        end loop;    end loop;end;/


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/414712.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号