创建存储过程
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关键字,不然会报错。