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 6243723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:11:45+00:00 2026-05-24T12:11:45+00:00

I have a to write a insert trigger on a tableA. which will perform

  • 0

I have a to write a insert trigger on a tableA. which will perform update with same table but different column. I am getting error while doing this. My trigger is

create or replace trigger trigger_A
after insert on table_A
begin
  update table_A set col1=1 where col1 is null;
end;

I have an application will perform col2 alone will be inserted and col1 will be kept null. so my trigger will give value for col1 once the row is inserted. But i am getting error saying “Trigger is failed and invalid” when a row is inserted.
How to do this. TIA.

  • 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-05-24T12:11:46+00:00Added an answer on May 24, 2026 at 12:11 pm

    If you want to assign a simple default value, the easiest way is to declare it on the table, using the DEFAULT clause.

    SQL> create table t42
      2    ( col1 number default 1 not null
      3      , col2 date)
      4  /
    
    Table created.
    
    SQL> insert into t42 (col2) values (sysdate)
      2  /
    
    1 row created.
    
    SQL> select * from t42
      2  /
    
          COL1 COL2
    ---------- ---------
             1 03-AUG-11
    
    SQL>
    

    This works with literals or pseudocolumns such as SYSDATE or USER. If you want to derive a more complicated value with a user-defined function or a sequence, you will need to use
    a trigger.

    Here is a new version of the table…

    SQL> create table t42
      2    ( col1 number default 1 not null
      3      , col2 date default sysdate
      4      , col3 varchar2(30) default user
      5      , col4 number )
      6  /
    
    Table created.
    
    SQL>
    

    … with a trigger:

    SQL> create or replace trigger t42_trg
      2      before insert or update
      3      on t42
      4      for each row
      5  begin
      6      if :new.col4 is null
      7      then
      8          :new.col4 := my_seq.nextval;
      9      end if;
     10  end;
     11  /
    
    Trigger created.
    
    SQL> insert into t42 (col1, col2, col3)
      2  values (99, sysdate, 'MR KNOX')
      3  /
    
    1 row created.
    
    SQL> select * from t42
      2  /
    
          COL1 COL2      COL3                                 COL4
    ---------- --------- ------------------------------ ----------
            99 03-AUG-11 MR KNOX                               161
    
    SQL>
    

    Note that although every column on the table is defaultable, I have to populate at least one column to make the SQL valid:

    SQL> insert into t42 values ()
      2  /
    insert into t42 values ()
                            *
    ERROR at line 1:
    ORA-00936: missing expression
    
    
    SQL>
    

    But I can pass in NULL to COL4 to get a completely defaulted record:

    SQL> insert into t42 (col4) values (null)
      2  /
    
    1 row created.
    
    SQL> select * from t42
      2  /
    
          COL1 COL2      COL3                                 COL4
    ---------- --------- ------------------------------ ----------
            99 03-AUG-11 MR KNOX                               161
             1 03-AUG-11 APC                                   162
    
    SQL>
    

    Caveat lector: my trigger uses the new 11g syntax. In previous versions we have to assign the sequence value using a SELECT statement:

    select my_seq.nextval
    into :new.col4
    from dual;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have created a trigger which i want to update a table field
I'm trying to write a table trigger which queries another table that is outside
In looking at similar questions like: Getting trigger to insert changed column values only
I'm working on an application so i have write an dll which contain a
I have a table A which maintains count of total users in Table B.
I have a table which have 4 fields. Col1 Guid Primary-Key (FK to another
I have a mysql legacy table which contains an client identifier and a list
I have an oracle table with a sequence and a trigger to autoincrement a
I have to create a trigger (not procedure) to update subtotal, shipping_charge, tax and
I have a table in SQL Server, tblMain. There's a trigger that when a

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.