среда, 22 января 2014 г.

Удаление table, view, procedure, sequence из Oracle по маске

set serveroutput on size 1000000

BEGIN
FOR r IN(

  select TABLE_NAME
    from USER_TABLES
      where TABLE_NAME like 'NF\_%' escape '\')

LOOP

  execute immediate 'drop table ' || r.table_name || ' cascade constraints';

END LOOP;

FOR r IN (

  select SEQUENCE_NAME
    from USER_SEQUENCES
      where SEQUENCE_NAME like 'NF\_%' escape '\')

LOOP

  execute immediate 'drop sequence ' || r.SEQUENCE_NAME;

END LOOP;

FOR r IN (

  select VIEW_NAME
    from USER_VIEWS
   where VIEW_NAME like 'NF\_%' escape '\')

LOOP

  execute immediate 'drop view ' || r.VIEW_NAME;

END LOOP;

FOR r IN (

  select OBJECT_NAME
    from USER_PROCEDURES
      where OBJECT_NAME like 'NF\_%' escape '\')

LOOP

  execute immediate 'drop procedure ' || r.OBJECT_NAME;

END LOOP;

exception when others then
   dbms_output.put_line(sqlerrm);
END;
/

Комментариев нет: