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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:06:37+00:00 2026-06-04T14:06:37+00:00

I have a plsql procedure to delete records from child and parent tables. I

  • 0

I have a plsql procedure to delete records from child and parent tables.

I would like to raise exception when child record found.

How can I do this?

CREATE OR REPLACE PROCEDURE myproc(
    p_id       number,
    p_id2      number,
    p_par3      number)
AS
BEGIN
 DELETE FROM   child_table
            WHERE   id1 = p_id and par=p_par3;

    DELETE FROM   parent_table
            WHERE   no = p_id2;
COMMIT;

EXCEPTION   
    WHEN OTHERS
    THEN
        --raise
END myproc;
/
  • 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-04T14:06:38+00:00Added an answer on June 4, 2026 at 2:06 pm

    Remove the exception block if you don’t want to catch the exception !

    CREATE OR REPLACE PROCEDURE myproc(p_id NUMBER, p_id2 NUMBER, p_par3 NUMBER) AS
    BEGIN
       DELETE FROM child_table
        WHERE id1 = p_id
          AND par = p_par3;
    
       DELETE FROM parent_table WHERE no = p_id2;
       COMMIT; /* do you really want to commit in a procedure? */
    END myproc;
    

    You don’t have to catch them all (exceptions are not pokemon). If you really insist on catching and re-raising you can use RAISE or RAISE_APPLICATION_ERROR:

    EXCEPTION
       WHEN OTHERS THEN
          raise_application_error(-20001 /* user-defined exception number 
                                            between -20999 and -20000 */,
                                  'your user-defined exception message',
                                  TRUE /* this will preserve the error stack */
                                  );
    END;
    

    If you want to be more specific and trap only the child exception, you will have to define the exception number because there is no predefined exception in PL/SQL for this error:

    CREATE OR REPLACE PROCEDURE myproc(p_id NUMBER, p_id2 NUMBER, p_par3 NUMBER) AS
       child_exists EXCEPTION;
       PRAGMA EXCEPTION_INIT(child_exists, -2292); /* raises ORA-02292 */
    BEGIN
       DELETE FROM child_table
        WHERE id1 = p_id
          AND par = p_par3;
    
       DELETE FROM parent_table WHERE no = p_id2;
       COMMIT; /* do you really want to commit in a procedure? */
    
    EXCEPTION
       WHEN child_exists THEN
          -- do something
          RAISE;
    END myproc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing tutorial from website http://www.plsqltutorial.com/plsql-procedure/ . I have run the code on apex:
I have an issue with psql. I am trying to select the records from
I have a select query on a relational table in a plsql procedure. I
I'm following a tutorial on PL/SQL http://www.plsqltutorial.com/plsql-procedure/ . I have created procedure with the
I have written a PLSQL stored procedure , i want to call the procedure
I'm using dbms_scheduler to execute a PL/SQL stored procedure. I would like to be
I wanted to have a function in PLSQL that would return an set of
I'm working on a project with a lot of plsql code and would like
Below is the procedure which i have taken from net..but while executing its giving
I have a parent/child relationship defined which, unfortunately, cannot be maintained via a foreign

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.