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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:44:28+00:00 2026-06-15T23:44:28+00:00

I am a newbie in PLSQL and I would like to create a trigger

  • 0

I am a newbie in PLSQL and I would like to create a trigger that checks first if there is a record in a table before making an update.
The code I got so far is:

CREATE OR REPLACE TRIGGER table_bu
BEFORE UPDATE ON employee
FOR EACH ROW
DECLARE
    v_employee_id:=employee.employee_ID%TYPE;
BEGIN
    SELECT employee_id INTO v_employee_id FROM employee;
EXCEPTION
    WHEN NO_DATA_FOUND THEN
        RAISE_APPLICATION_ERROR (-20001,'data not found');
END;

How I can create a trigger that checks up if a record exists in the table and if it does not exists does not allow the update.
My table estructure is:

employee_id NUMBER
employee_name VARCHAR(20)
employee_salary NUMBER
...

Thanks

  • 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-15T23:44:29+00:00Added an answer on June 15, 2026 at 11:44 pm

    You are on a wrong way. The trigger as it is will throw runtime ‘Mutating table’ error even after fixing syntax error – you missed semicolon after raise_application_error(also it should take 2 arguments, not one). Correct syntax :

    EXCEPTION
    WHEN NO_DATA_FOUND THEN
        RAISE_APPLICATION_ERROR (-20001, 'data not found'); -- 1st parameter -error code
    

    Update

    As far as I understand the updated version of the question, you want to show error if record doesn’t exist. The problem with row level trigger approach is that it won’t be executed if nothing is found due to condition in WHERE. The simplest way is to check number of rows affected on client side and raise an error there. Or you can write a procedure that checks sql%rowcount after executing desired update, and then throw an exception if it’s 0.
    If you prefer to do in a hard way, you can create package variable which of type employee.employee_ID%TYPE, before update statement level trigger that resets variable (say set it to null), after update row level trigger that sets this variable to NEW.employee_ID, and after update statement level trigger that throws an exception if the variable is null. Note: this will properly work for individual updates only.

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

Sidebar

Related Questions

Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Am a Oracle PL/SQL newbie. Basically, I have a table created as follows: CREATE
Newbie here. I am looking at company code. It appears that there are NO
Newbie question. I want to do something like: SELECT c1,c2,c3 FROM TABLE t1 UNION
Newbie question here! I'm building a simple application that allows users to create and
Newbie SQL question here --> I've got an Occurrences table that contains a row
Newbie question here, is there any inbuilt PHP tag that can be used to
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that
Newbie question: There are three types of Asp.Net controls : HTML server controls, Web
newbie here .. wondering why in the table i get something called '[object node]'

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.