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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:35:19+00:00 2026-06-18T07:35:19+00:00

What is problem in my trigger? I use toad for oracle After executing this

  • 0

What is problem in my trigger?
I use toad for oracle
After executing this sql toad show this message and no more!:

Warning: compiled but with compilation errors

and trigger does not work

my trigger is here:

CREATE OR REPLACE TRIGGER trg_delete_mmtp_user_feature
   BEFORE DELETE
   ON mmtp_user
   FOR EACH ROW
BEGIN
-- for these cases delete not allowed
   IF ((SELECT COUNT (*)
          FROM payment p INNER JOIN mmtp_user mt
               ON mt.customer_id = p.requester_id
         WHERE p.rp_reason_id = 20 AND mt.mmtp_user_id = :OLD.mmtp_user_id) >
                                                                             0
      )
   THEN
      raise_application_error
             (-20654,
              'Query has attempted to delete MMTP_USER with existing payment'
             );

   ELSE                            --befor deleting features should be deleted
      DELETE FROM mmtp_user_feature
            WHERE mmtp_user_id = :OLD.mmtp_user_id;
   END IF;
END;
/

and for deleting i receive this message:

ORA-04098: trigger 'DEVX2.TRG_DELETE_MMTP_USER_FEATURE' is invalid and failed re-validation
  • 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-18T07:35:21+00:00Added an answer on June 18, 2026 at 7:35 am

    The reason you get a compilation error is that we cannot use SELECT statements in IF clauses. So you need to break it out like this:

    ....
    DECLARE
        n pls_integer;
    BEGIN
        SELECT COUNT (*)
        into n
        FROM payment p INNER JOIN mmtp_user mt
                   ON mt.customer_id = p.requester_id
        WHERE p.rp_reason_id = 20 AND mt.mmtp_user_id = :OLD.mmtp_user_id
    -- for these cases delete not allowed
       IF n > 0
       THEN
    ....
    

    Having solved that you will find, as Florin points, that you will get a runtime mutating table error. Oracle throws this error when we put a query in a trigger which accesses the table that owns the trigger. It happens because the table is in an unstable state and the outcome of the query is unpredictable.

    Mutating table errors are almost always an indicator of a bad data model, with the culprit being insufficient normalization. That means fixing them requires a knowledge of the business rules. In this case the obvious solution would be:

    SELECT COUNT (*)
    into n
    FROM payment p 
    WHERE p.requester_id = :OLD.customer_id
    AND p.rp_reason_id = 20 
    

    This would work if there is a one-to-one relationship between user_id and customer_id. It there is not such a relationship you’ll have to figure out a solution using your knowledge of your business rules.

    Incidentally, using COUNT(*) to test for existence is not a solution which scales. It will take a long time for a customer with many payments. That’s a lot of wasted effort when all you require is that they have at least one such record. Adding and rownum = 1 into the query will reduce the needless work.

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

Sidebar

Related Questions

I have a problem with compiling an Oracle trigger via SQL*PLUS - I don't
i often use but i have this problem. if there is a whose action
I use this script to navigate with keyboard arrow keys. But the problem is
I am new to database and am struggling with a problem. I use SQL
My current code that i use is this: <script type=text/javascript> $(document).ready(function(){ $('#on_holiday').trigger('click'); }); </script>
I have this code (mySql 5.1.36) CREATE TRIGGER problem_description AFTER INSERT ON problem_description FOR
I've been having performance problems with an SQL trigger. The problem relates to performing
I'm having a problem creating a trigger on a database for a project I've
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
I have a problem with Jquery function getJSON, the action url does not trigger

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.