Results 1 to 5 of 5

Thread: Cursor problem!

  1. #1
    Join Date
    Aug 2005
    Posts
    40

    Unanswered: Cursor problem!

    Hello, I wrote this cursor and would like to know why it will not execute?
    I called it drop.sql and tried to execute from sqlplus, it just sits there and does nothing.
    I am a newbie at pl/sql.

    declare
    cursor cCur is
    select object_type, object_name
    from dba_objects
    where owner='TRN01';
    begin
    for rCur in cCur loop
    if rCur.object_type='TABLE' then
    execute immediate('drop table TRN01.'||rCur.object_name);
    end if;
    if rCur.object_type='VIEW' then
    execute immediate('drop view TRN01.'||rCur.object_name);
    end if;
    if rCur.object_type='FUNCTION' then
    execute immediate ('drop function TRN01.'||rCur.object_name);
    end if;
    if rCur.object_type='PROCEDURE' then
    execute immediate ('drop procedure TRN01.'||rCur.object_name);
    end if;
    if rCur.object_type='SEQUENCE' then
    execute immediate ('drop sequence TRN01.'||rCur.object_name);
    end if;
    end loop;
    end;

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    declare
    cursor cCur is
    select object_type, object_name
    from dba_objects
    where owner='TRN01';
    begin
    for rCur in cCur loop
    execute immediate ('drop '||rCur.object_type  || ' TRN01.'||rCur.object_name);
    end loop;
    end;
    /
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Aug 2005
    Posts
    40
    I started out using a similiar statement and I kept getting errors.
    When I ran your statement, I received this:

    ERROR at line 1:
    ORA-02429: cannot drop index used for enforcement of unique/primary key
    ORA-06512: at line 8

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    You really should NOT be doing DDL from PL/SQL.
    An error free solution is "DROP USER TRN01 CASCADE".
    If you wish to proceed down the current path, then You're On Your Own (YOYO!) to deal with object interrelationships.
    It gets uglier when you have multiple level PK & FK constraints.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Aug 2005
    Posts
    40
    thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •