Pages

Search This Blog

Tuesday, November 29, 2011

[Oracle] How to see last sql statements executed

Recently we get into scenario where we need to see that which sql statements are being executed by activity upload.


So here is an easy way to do this:


select sql_text from v$sql where rownum<=100 and parsing_schema_name='NC_SDA_1_301';


Parsing Schema Name ; should be your schema name for which you need to see the sql statements executed on.

Thursday, November 24, 2011

[Oracle] Enable / Disable all constraints in DB

Disable Constraints:


BEGIN

FOR c IN

(SELECT c.owner, c.table_name, c.constraint_name

FROM user_constraints c, user_tables t

WHERE c.table_name = t.table_name

AND c.status = 'ENABLED'

ORDER BY c.constraint_type DESC)

LOOP

dbms_utility.exec_ddl_statement('alter table ' || c.owner || '.' || c.table_name || ' disable constraint ' || c.constraint_name);

END LOOP;

END;


Enable Constraints:


BEGIN

FOR c IN

(SELECT c.owner, c.table_name, c.constraint_name

FROM user_constraints c, user_tables t

WHERE c.table_name = t.table_name

AND c.status = 'DISABLED'

ORDER BY c.constraint_type)

LOOP

dbms_utility.exec_ddl_statement('alter table ' || c.owner || '.' || c.table_name || ' enable constraint ' || c.constraint_name);

END LOOP;

END;