vendredi 16 septembre 2011

Oracle PL/SQL Data Scanner Script v0.2

Cette version du script permet de scanner toutes les tables d'une base de données, toutes les colonnes de chaque table, et parcoure la première ligne de la table ; La valeur de chaque colonne de la première ligne est obtenue.


-- Oracle PL/SQL Data Scanner Script v0.2
-- By IO-ESG (09/2011)

declare
myvar varchar2(1024);
i number;
myresult varchar2(1024);
myval varchar2(1024);
nbrec number;
valeur varchar2(256);

begin
dbms_output.enable(500000);
for t in (select t.* from all_tables t where t.owner like 'OWNER') loop
myvar := t.table_name;
dbms_output.put_line('table name = ' || myvar);

begin
execute immediate ('select count(*) from ' || t.table_name)
into nbrec;
dbms_output.put_line(' Nb records = ' || nbrec);
exception
when others then
dbms_output.put_line(' *** exception count ***');
end;

for u in (select u.* from all_tab_columns u where u.table_name = myvar) loop
dbms_output.put_line(' column name = ' || u.column_name);

begin
execute immediate('select v.' || u.column_name || ' from ' || u.table_name || ' v')
into valeur;
exception
when others then
dbms_output.put_line(' *** exception value ***');
end;

dbms_output.put_line(' VALUE = ' || valeur);

end loop;
end loop;
end;