[oracle存储过程]输出数据库中表的数量

30 篇文章 0 订阅
6 篇文章 0 订阅

创建存储过程

create or replace procedure countTableNum is
  x number;
  y number;
  z number;
begin
  select count(*) into x from user_tables;
  select count(*) into y from user_tables where num_rows=0;
  select count(*) into z from user_tables where num_rows!=0;
  dbms_output.put_line('所有表的数量:'||x);
  dbms_output.put_line('空表数量:'||y);
  dbms_output.put_line('非空表数量:'||z);
end;

执行存储过程

begin
  countTableNum();
end;

补充:

如果只想测试下存储过程功能,并不想创建存储过程(执行一次就没了)。可以这样写

declare
procedure printTableNum is
  x number;
  y number;
  z number;
begin
  select count(*) into x from user_tables;
  select count(*) into y from user_tables where num_rows=0;
  select count(*) into z from user_tables where num_rows!=0;
  dbms_output.put_line('所有表的数量:'||x);
  dbms_output.put_line('空表数量:'||y);
  dbms_output.put_line('非空表数量:'||z);
end;
begin
  printTableNum();
end;

注:即使plsql中的声明部分为空,也要加上declare关键字,不然会报错。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值