oracle如何批量查询数据表记录数
发布网友
发布时间:2022-04-08 07:00
我来回答
共3个回答
懂视网
时间:2022-04-08 11:21
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
create or replace function count_rows(table_name in varchar2,
owner in varchar2 default null)
return number
authid current_user
IS
num_rows number;
stmt varchar2(2000);
begin
if owner is null then
stmt := ‘select count(*) from "‘||table_name||‘"‘;
else
stmt := ‘select count(*) from "‘||owner||‘"."‘||table_name||‘"‘;
end if;
execute immediate stmt into num_rows;
return num_rows;
end;
然后通过计算函数进行统计
select table_name, count_rows(table_name) nrows from user_tables
本文出自 “技术成就梦想” 博客,请务必保留此出处http://pizibaidu.blog.51cto.com/1361909/1683502
Oracle查询数据库中所有表的记录数
标签:oracle 数据库 表 记录数 统计
热心网友
时间:2022-04-08 08:29
首先,oracle中有存放表名的系统表,所以你那个tcmz有点多余
declare
v_tablename varchar2(60);
v_count int;
v_sql varchar2(2000);
cursor cur_tablename is
select table_name from user_tables;
begin
open cur_tablename;
loop
fetch cur_tablename into v_tablename;
exit when cur_tablename%notfound;
v_sql:='select count(*) from '||v_tablename||'';
execute immediate v_sql into v_count;
dbms_output.put_line(v_tablename||':'||v_count);
end loop;
close cur_tablename;
end;
如果非要用你那个的话,可以这样改
declare
v_tablename varchar2(60);
v_count int;
v_sql varchar2(2000);
cursor cur_tablename is
select 表名 from tcmz;--字段名你替换成你自己的
begin
open cur_tablename;
loop
fetch cur_tablename into v_tablename;
exit when cur_tablename%notfound;
v_sql:='select count(*) from '||v_tablename||'';
execute immediate v_sql into v_count;
dbms_output.put_line(v_tablename||':'||v_count);
end loop;
close cur_tablename;
end;
热心网友
时间:2022-04-08 09:47
DECLARE v_sql varchar2(300);
begin
FOR COL IN (select distinct tcmz from a) loop
v_sql := null;
v_sql := 'update a set 记录数 = (select count(1) from '||COL.tcmz||') where tcmz
= '''||COL.tcmz||'''';
execute immediate v_sql;
commit;
end loop;
end;