Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trigger to rename a table before create a new one with same name

3672540Feb 7 2019 — edited Feb 8 2019

Hi all,

I have a table_1. I want to create a new table called always table_1, with different column but I also want to rename the old table_1. I have create the following trigger

create or replace TRIGGER test_trigger

  before create on database

declare

   v_count number;

BEGIN

        select count(*)

        INTO v_count

        from all_tables

        where table_name = ora_dict_obj_name;

        IF v_count >0 THEN

            EXECUTE IMMEDIATE 'ALTER TABLE TABLE_1 RENAME TO TABLE_1_OLD';

        END IF;

    END IF;

END;

But if I run the create script for table 1 , I have always the error that the table already exists .

Could you help me please?

Regards

Luca

Comments
Post Details
Added on Feb 7 2019
9 comments
2,708 views