通过SQL*Plus在Oracle数据库中的几个表显示计数
我正在尝试在Oracle数据库中显示所有类似名称的表的计数。查询将通过命令行中的SQL*Plus运行。我已经编写了以下代码:
DECLARE
ctr number;
cursor to_check is
select table_name from user_tables
where table_name like '%REF%' or table_name like '%CNF%'
order by table_name;
BEGIN
set serveroutput on size 100000;
for rec in to_check loop
execute immediate 'select count(*) into :ctr from ' || rec.table_name;
dbms_output.put_line(rec.table_name || ' ' || ctr);
end loop;
END;
但是,我没有收到此代码的输出。 DBMS_OUTPUT是否有问题?还是我错过了一种更优雅的拉动和显示此信息的方式?
I'm attempting to display the count of all tables of a similar name in an Oracle database. The query will run via SQL*Plus at the command line. I've written the following code:
DECLARE
ctr number;
cursor to_check is
select table_name from user_tables
where table_name like '%REF%' or table_name like '%CNF%'
order by table_name;
BEGIN
set serveroutput on size 100000;
for rec in to_check loop
execute immediate 'select count(*) into :ctr from ' || rec.table_name;
dbms_output.put_line(rec.table_name || ' ' || ctr);
end loop;
END;
However, I'm not receiving the output of this code. Is there an issue with the dbms_output? Or am I missing a more elegant way of pulling and displaying this information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有点主观,但是...
您可以避免使用XML技巧避免使用PL/SQL(并需要客户端显示输出)。您可以使用
dbms_xmlgen
生成包含所需信息的XML文档:提取值
然后将其用作CTE或INLINE视图,然后使用XMLTable: db<
That's a bit subjective, but...
You can avoid PL/SQL (and needing the client to display the output) with an XML trick. You can use
dbms_xmlgen
to generate an XML document containing the information you want:And then use that as a CTE or inline view and extract the values using XMLTable:
db<>fiddle with a couple of dummy tables.
上的ServerOutput设置是
sql*plus
命令。它不能出现在PL/SQL块中。它必须是一个单独的命令(并且仅在sql*plus
客户端或实现sql*sqlplus
'sset set set
的客户端或客户端中有意义/代码>命令)。在您的PL/SQL块执行之前,需要完成。
的语法即时执行
将是set serveroutput on
is aSQL*Plus
command. It cannot appear inside a PL/SQL block. it has to be a separate command (and is only meaningful in theSQL*Plus
client or a client that implements a subset ofSQL*Plus
'sset
commands). That would need to be done before your PL/SQL block executes.The syntax for
execute immediate
would be