Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9106677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:23:40+00:00 2026-06-17T02:23:40+00:00

When a table create in schema (MYSCHEMA), I need to create a trigger that

  • 0

When a table create in schema (MYSCHEMA), I need to create a trigger that generate a ID column (from sequence) before insert in each created table..
How can I realize this?

I know, how I can realize generation of ID column through trigger and sequence, something like this:

CREATE OR REPLACE TRIGGER TR1
  BEFORE INSERT ON TB1
  FOR EACH ROW
BEGIN
  SELECT SQ1.nextval
    INTO :new.primary_key_column
    FROM dual;
END;

But I don’t know, how I can use AFTER CREATE ON SCHEMA trigger to create trigger after CREATE TABLE in my schema with BEFORE INSERT…

I’ve written this code:

CREATE OR REPLACE TRIGGER /*APPROOT*/after_create_table_trigger
AFTER CREATE ON APPROOT.SCHEMA
DECLARE 
TABLE_NAME VARCHAR2(100);
BEGIN
IF ORA_DICT_OBJ_TYPE = 'TABLE' THEN
SELECT ORA_DICT_OBJ_NAME INTO TABLE_NAME FROM DUAL;
EXECUTE IMMEDIATE 
('CREATE OR REPLACE TRIGGER id_table_gen
  BEFORE INSERT ON ' || TABLE_NAME ||
  ' FOR EACH ROW
   BEGIN
    SELECT APPROOT.AE_IDSEQ.NEXTVAL
     INTO :new.ID
     FROM dual;
   END;');
END IF;
END;
/

Then I’ve created test table with one field – ID, but my trigger doesn’t work…
I think the reason is wrong using of event attribute function ora_dict_obj_name.

Could somebody give me advice about this?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:23:41+00:00Added an answer on June 17, 2026 at 2:23 am

    works ok if i put the schema name in the DDL.

    SQL> connect sys/test as sysdba
    Connected.
    SQL> CREATE OR REPLACE TRIGGER after_create_table_trigger
      2  AFTER CREATE ON TEST.SCHEMA
      3  DECLARE
      4  TABLE_NAME VARCHAR2(100);
      5  BEGIN
      6  IF ORA_DICT_OBJ_TYPE = 'TABLE' THEN
      7  SELECT ORA_DICT_OBJ_NAME INTO TABLE_NAME FROM DUAL;
      8  EXECUTE IMMEDIATE
      9  ('CREATE OR REPLACE TRIGGER ID_TABLE_GEN
     10    BEFORE INSERT ON TEST.' || TABLE_NAME ||
     11    ' FOR EACH ROW
     12     BEGIN
     13      SELECT TEST.AE_IDSEQ.NEXTVAL
     14       INTO :new.ID
     15       FROM dual;
     16     END;');
     17  END IF;
     18  END;
     19  /
    
    Trigger created.
    
    SQL> connect test/test
    Connected.
    SQL> create table mytab(id number primary key, a varchar2(1));
    
    Table created.
    
    SQL> insert into mytab (a) values ('a');
    
    1 row created.
    
    SQL> select * From mytab;
    
            ID A
    ---------- -
             1 a
    
    
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    

    p.s. no need to do

    SELECT ORA_DICT_OBJ_NAME INTO TABLE_NAME FROM DUAL;
    

    just paste it into the command.

    CREATE OR REPLACE TRIGGER ID_TABLE_GEN
      BEFORE INSERT ON APPROOT.' || ORA_DICT_OBJ_NAME ||
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a schema that essentially looks like this: CREATE TABLE `data` ( `id`
I've just created anew schema & want to create a new table. When ever
So here's my schema (give or take): cmds.Add(@CREATE TABLE [Services] ([Id] INTEGER PRIMARY KEY,
With the following DB schema: CREATE TABLE master ( id integer primary key autoincrement,
I created a table like this CREATE TABLE pull_dtl ( source_schema VARCHAR2(4000), source_tablename VARCHAR2(4000),
I have an orders table with a schema like this. CREATE TABLE orders (
I need to add a select box next to each field in a create/update
I'm trying to create a function to insert data into a table. The query
I have a tool that generates a DDL script create table ATTRIBUTE_VALUE ( id
This is my schema: CREATE TABLE item ( id integer NOT NULL PRIMARY KEY

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.