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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:40:53+00:00 2026-05-31T02:40:53+00:00

I have account table as this– create table account ( acct_id int, cust_id int,

  • 0

I have account table as this–

create table account
(
acct_id int,
cust_id int,
cust_name varchar(20)  
)

insert into account values(1,20,'Mark');
insert into account values(2,23,'Tom');
insert into account values(3,24,'Jim');

I want to create a trigger which will ensure that no records can be inserted or update in account table having acct_id as 2 and cust_id as 23.

My code is —

create trigger tri_account
before insert or update
on account
for each row
begin
    IF (:new.acct_id == 2 and :new.cust_id == 23) THEN 
        DBMS_OUTPUT.PUT_LINE('No insertion with id 2 and 23.');
rollback;
    END IF; 
end;

so this trigger is created , but with compilation error.
now when I insert any record with acct_id as 2 and cust_id as 23,it doesent allow.
But I get an error saying
ORA-04098: trigger ‘OPS$0924769.TRI_ACCOUNT’ is invalid and failed re-validation

I don’t understand this.I also want to show a message that dis insertion is not possible.
please Help…

  • 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-31T02:40:54+00:00Added an answer on May 31, 2026 at 2:40 am
    1. The equality operator in Oracle is =, not ==.
    2. You cannot commit or rollback in a trigger. You can throw an exception which causes the triggering statement to fail and to be rolled back (though the existing transaction will not necessarily be rolled back).
    3. It does not appear that this trigger compiled successfully when you created it. If you are using SQL*Plus, you can type show errors after creating a PL/SQL object to see the compilation errors.
    4. You should never write code that depends on the caller being able to see the output from DBMS_OUTPUT. Most applications will not so most applications would have no idea that the DML operation failed if your trigger simply tries to write to the DBMS_OUTPUT buffer.

    Putting those items together, you can write something like

    create trigger tri_account
    before insert or update
    on account
    for each row
    begin
        IF (:new.acct_id = 2 and :new.cust_id = 23) THEN 
            raise_application_error( -20001, 'No insertion with id 2 and 23.');
        END IF; 
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this: create table account ( id int identity(1,1) primary key,
I am having trouble inserting values into my Account table that's in a SQL
I have a table like this: |sub_account|name|email| |-----------|----|-----| // same account and same name:
I have a table like this (Oracle, 10) Account Bookdate Amount 1 20080101 100
I have one table like this account_id (INT) inviter_id (INT) Now, logged in user
I am new to Hibernate. I have Order and Account table in DB, CREATE
I have a table with several account fields like this: MAIN_ACCT GROUP_ACCT SUB_ACCT I
I have the following table: Table Account{ [...] email varchar(100), [...] } and a
I have this table where you add taxes. |Name | Rate | Description |
I have the following problem: I have an account table and an entries for

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.