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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:34:58+00:00 2026-05-18T06:34:58+00:00

I wrote a trigger in mysql that checks to see if a person is

  • 0

I wrote a trigger in mysql that checks to see if a person is able to check out another library item. The checkout limit I have set is 3. I need to convert this to an Oracle trigger but am having lots of problems.

Here is my MySQL code:

DELIMITER //
DROP TRIGGER IF EXISTS library.CheckBorrowsTable//
CREATE TRIGGER CheckBorrowsTable
BEFORE INSERT ON library.Borrows
FOR EACH ROW
BEGIN
IF ((SELECT COUNT(*) FROM library.Borrows WHERE libraryID = new.libraryID) >= 3)THEN
SET new = NULL;
END IF;
END//
DELIMITER ;

Here is my Oracle code:

IF((SELECT COUNT(libraryID) FROM Borrows WHERE libraryID = :NEW.libraryID) >= 3) THEN
:NEW = NULL;
END IF;

There are other portions to my Oracle code but Oracle Express Edition adds those parts (Begin, End etc…)

  • 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-18T06:34:59+00:00Added an answer on May 18, 2026 at 6:34 am

    A row-level trigger on table A (i.e. library.borrows) cannot query table A. If you do so, you will get a mutating table exception (unless you can guarantee that you will only ever do single-row inserts with the VALUES clause). So that would not be considered a good development practice in Oracle.

    The most logical way to implement this sort of requirement would not be via a trigger. Instead, if your application calls a stored procedure API, you would have a stored procedure (i.e. CHECK_OUT) that first queries the table to determine how many books an individual has checked out and inserts the row into the BORROWS table only if the patron is below his or her limit.

    A second approach is to store the number of items checked out in a separate table. If you had a PATRONS table with a NUM_CHECKED_OUT column and your BORROWS table had a PATRON_ID to indicate who had borrowed the book, your trigger could do something like

    CREATE OR REPLACE TRIGGER CheckBorrowsTable
      BEFORE INSERT ON library.borrows
      FOR EACH ROW
    BEGIN
      UPDATE patrons p
         SET p.num_checked_out = p.num_checked_out + 1
       WHERE p.patron_id = :new.patron_id
    END;
    

    along with a CHECK constraint on the PATRONS table to ensure that NUM_CHECKED_OUT never exceeds 3.

    Barring that, it is possible, though rather cumbersome, to work around the mutating table error with the “three trigger solution”.

    1. A BEFORE INSERT statement level
      trigger clears out a collection that
      you have created in a package.
    2. A BEFORE INSERT row level trigger
      writes the primary key (or ROWID) of
      the row being modified into the
      collection.
    3. An AFTER INSERT statement
      level trigger reads the data from
      the collection, queries the table,
      and determines if any of the inserts
      have violated the business rule. If
      they did, throw an exception.

    As you might imagine, however, the three trigger solution involves a fair number of moving pieces so it’s not particularly advisable.

    You can also implement this sort of thing with a fast refreshable materialized view, but I don’t believe that is an option in the express edition of the database (though I could be wrong on that).

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

Sidebar

Related Questions

I wrote a trigger that updates local table and similar table on linked server.
I wrote a trigger that needs to do some different work on a table
Trigger actually. But how do i make this in mysql-workbench. So that anytime i
I need to be able to set a MySQL user variable that is used
I need to write a trigger that rounds a value whenever it is inserted/updated
Please help me to write a trigger that adds new rows to a table.
I'm trying to write an after update trigger that does a batch update on
So I'm trying to write a SQL Server Trigger that will call an ASP.Net
I wrote a menu application that has no persistent window or standard menu. When
I have a NativeActivity derived activity that I wrote that is to use bookmarks

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.