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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:49:43+00:00 2026-06-14T18:49:43+00:00

just wonder is it possible to create a trigger to check on a specify

  • 0

just wonder is it possible to create a trigger to check on a specify constraint base on monthly basis.

eg.
table rent
|ID|Member|book|
———————-
1 | John |fairytale|

2 | John |friction|

3 | John |comic|

4 | John |magazine|

constraint : member are only allow to borrow 4 books monthly.

i thought of using count(book) <= 4 but does not know how to implement the monthly basis constraint.

Any suggestion?

  • 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-14T18:49:46+00:00Added an answer on June 14, 2026 at 6:49 pm

    using a trigger, whilst it seems to work, is a dangerous way of doing it, as sessions running in parallel wont see the inserted data from the inprogress session.
    you can do it via a materilized view:

    SQL> create table rent (id number primary key, member varchar2(30), book varchar2(20), date_rented date);
    
    Table created.
    
    SQL> create index rent_ix1 on rent ( member, date_rented);
    
    Index created.
    
    SQL> create materialized view log on rent with rowid(member,date_rented)
      2  including new values;
    
    Materialized view log created.
    
    SQL> create materialized view rent_month_check
      2  refresh fast on commit
      3  as
      4  select trunc(date_rented, 'mm') month, member, count(*) rentals
      5    from rent
      6   group by trunc(date_rented, 'mm'), member;
    
    Materialized view created.
    
    SQL> alter table rent_month_check
      2  add constraint rent_month_check_ck1 check (rentals <= 4);
    
    Table altered.
    
    SQL> insert into rent values(1, 'DazzaL', 'crime', sysdate);
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> insert into rent values(2, 'DazzaL', 'mystery', sysdate+1);
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> insert into rent values(3, 'DazzaL', 'fantasy', sysdate+2);
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> insert into rent values(4, 'DazzaL', 'politics', sysdate+3);
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> insert into rent values(5, 'DazzaL', 'thriller', sysdate+4);
    
    1 row created.
    
    SQL> commit;
    commit
    *
    ERROR at line 1:
    ORA-12008: error in materialized view refresh path
    ORA-02290: check constraint (TEST.RENT_MONTH_CHECK_CK1) violated
    
    
    SQL> select * from rent_month_check;
    
    MONTH     MEMBER                            RENTALS
    --------- ------------------------------ ----------
    01-NOV-12 DazzaL                                  4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just learning .net and i wonder if it is possible to create
I just wonder if it is possible to only use CSS but not javascript
I wonder whether I can use knitr markdown to just create a report on
I wonder if it is possible to create a FIFO queue with mongodb and
I have found SWTChart library and just wonder how it would be possible to
Possible Duplicate: Which method performs better: .Any() vs .Count() > 0? I just wonder
Just wonder if it is possible to assign a theme to a page in
Just wonder how much cost to raise a java exception (or to call native
I just wonder there a way to display the files in document directory with
I just wonder whether there will be any conflict if two service intents are

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.