PLSQL code to query against all (similar) tables in database - oracle



I was playing around with some plsql code today.Just posting this sample plsql code as I thought this can help people.

This is a sample code that will search for all tables with name  ABC,ABC1,ACB2 in all schema's in database and execute a NOAUDIT against these tables. This sql can be modified to accommodate any changes where you want to run a query against all tables & schema's.


sample code:

declare
    result sys_refcursor;
    strTableName Varchar2(100);
strTableName1 Varchar2(100);
    strQuery varchar2(4000);
begin

open result for
    select owner,table_name from all_tables where
    table_name in ('ABC','ABC1',ABC2') order by table_name;

loop
    fetch result into strTableName,strTableName1;
    exit when result%notfound;
     
    DBMS_OUTPUT.PUT('NOAUDIT DELETE,UPDATE on '||strTableName||'.'||strTableName1||';');
   
strQuery := 'NOAUDIT DELETE,UPDATE on '||strTableName||'.'||strTableName1||' ';
 
    execute immediate strQuery;
 DBMS_OUTPUT.PUT_LINE(' ');
      DBMS_OUTPUT.PUT_LINE('SUCCESFULL');
end loop;

close result;

end;
/


Note : you can edit this part to what ever you want. >>>> NOAUDIT DELETE,UPDATE on

Comments

Popular posts from this blog

chr function and its values - CHR and ASCII values

IMPDP SHOW=Y, sqlfile=test.sql

ORACLE FAL_CLIENT and FAL_SERVER explained