Saturday, January 5, 2008

Oracle - Some helpful queries

1) I had one requirement to check all the count for all the tables in a schema

Here is the pl/sql block that I used. Not sure if there is any shortcut method.

DECLARE
cnt NUMBER;
cntsql VARCHAR2(100);
CURSOR alltab IS
SELECT object_name FROM all_objects
WHERE object_type='TABLE' AND
owner='Schema name' AND object_name LIKE '< Table Name Search Character>%'
ORDER BY object_name;
BEGIN
FOR c1 IN alltab LOOP
cntsql:='Select count(*) from .'||c1.object_name;
EXECUTE IMMEDIATE(cntsql) INTO cnt;
dbms_output.put_line(c1.object_name||','||cnt);
END LOOP;
END;

To be Continued ..............