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

  • Home
  • SEARCH
  • 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 8008691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:13:01+00:00 2026-06-04T18:13:01+00:00

I have a trigger that verifies if a field is null: create or replace

  • 0

I have a trigger that verifies if a field is null:

create or replace trigger trig1
after insert on table_1
for each row
begin
if ((select table2.column2 from table2 where table2.id= :new.id) isnull) then
update table2 set table2.column2 = :new.column1 where table2.id = :new.id;
end if;
end trig1;
.
run;

I get an error that the trigger is created with compilation errors. I don’t know what the problem is. I use Oracle SQL*Plus 10.2.0

  • 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-04T18:13:03+00:00Added an answer on June 4, 2026 at 6:13 pm

    The PL/SQL syntax doesn’t allow for including SQL statements in the IF clause.

    The correct approach is to separate out the SELECT statement and then test for its result. So that would be:

    create or replace trigger trig1 
    after insert on table_1 
    for each row 
    declare
        v table2.column2%type;
    begin
        select table2.column2 
        into v
        from table2 
        where table2.id= :new.id;
    
        if v is null
        then 
            update table2 
            set table2.column2 = :new.column1 
            where table2.id = :new.id; 
        end if; 
    end trig1;
    

    Note that this does not handle the existence of multiple rows in table2 matching the criteria, or indeed there being no matching rows. It also doesn’t handle locking.

    Also, bear in mind that code like this doesn’t function well in multi-user environments. That’s why I mentioned locking. You ought really to use procedural logic to handle these sorts of requirements. Although as is often the case with ill-conceived triggers the real culprit is a poor data model. table2.column2 should have been normalised out of existence.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a trigger that sets a datetime field in a table row when
I have a trigger that looks something like this: create or replace TRIGGER cluster_check
I have a trigger that looks like below: create trigger theTrig insert on table_A
We have created a table with a trigger that updates a ModifiedDate field in
I have a trigger for insert/update/delete. That is working fine. Also, I need the
I have a statement level trigger that fires whenever INSERT UPDATE or DELETE operations
How could I have a trigger that updates a certain field when the system
I have a trigger that stores changes made in a separate table when a
I have had to make changes to a trigger and assumed that running an
I have found that dragend event in Google Map also trigger the click event

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.