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

  • Home
  • SEARCH
  • 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 8337329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:16:32+00:00 2026-06-09T04:16:32+00:00

I am trying to define three database tables – USERNAME, USER_SESSIONS, and TOOLBOX_DIRS_REGISTERED. I

  • 0

I am trying to define three database tables – USERNAME, USER_SESSIONS, and TOOLBOX_DIRS_REGISTERED. I can define the first two of these without any problems, but the last one is causing me a bit of grief. Ideally I would like to define it as is shown in the code block below, however I believe that sub-queries cannot be used within check constraints?

The code block immediately below shows how I would like to define the table TOOLBOX_DIRS_REGISTERED. The start of the code block also contains some comments which attempt to explain my thoughts about certain constraints which the table definition uses.

-- Constraint : USERNAME_FK
-- ========================
--
-- USERNAME must contain a username which has been added to the table USERNAME.
--
-- Constraint : USER_SESSION_ID_FK
-- ===============================
--
-- USER_SESSION_ID must contain a user session ID which has been added to the table 
-- USER_SESSION.
--
-- Constraint : check_user_session_id
-- ==================================
--
-- In addition to the above constraint, USER_SESSION_ID must also belong to the 
-- username which is contained within USERNAME.

create table
TOOLBOX_DIRS_REGISTERED
(
 DIRNAME         varchar2(100) not null,
 USERNAME        varchar2(32)  not null,
 USER_SESSION_ID varchar2(32)  not null,
 AUTO_REGISTER   char          not null,
 constraint
   TOOLBOX_DIRS_REGISTERED_PK
   primary key (DIRNAME),
 constraint
   USERNAME_FK
   foreign key (USERNAME)
   references USERS(USERNAME),
 constraint
   USER_SESSION_ID_FK
   foreign key (USER_SESSION_ID)
   references USER_SESSIONS(USER_SESSION_ID),
 constraint
   check_user_session_id
   check
   (
    USERNAME in
    (
     select USERNAME from USER_SESSIONS
     where USER_SESSIONS(USER_SESSION_ID) = USER_SESSION_ID
    )
   )
);

Does anyone know of a way around this problem, i.e. the use of the sub-query in the definition of the check constraint ‘check_user_session_id’? I read on Stackoverflow that Materialized views can be used instead of sub-queries in this particular situation. The trouble is, if I use a Materialized view, then I would want to make sure it was up to date at the time the check constraint was being performed. So what I did was implement the Materialized view along with a Trigger which called dbms_mview.refresh on the Materialized view. This is all fine, except that Oracle complains that it cannot COMMIT in a Trigger. Urgh! The exact message it gives me is ;

ERROR at line 2:
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2760
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2740
ORA-06512: at "SYSTEM.SIMULAB_MVIEW", line 19
ORA-06512: at "SYSTEM.TRIG_TOOLBOX_DIRS_REGISTERED", line 3
ORA-04088: error during execution of trigger 'SYSTEM.TRIG_TOOLBOX_DIRS_REGISTERED'

I’m assuming that Oracle is attempting to automatically perform a commit after it refreshes the Materialized view and that’s what it is complaining about?

My Trigger is defined as follows ;

create or replace trigger TRIG_TOOLBOX_DIRS_REGISTERED
  before insert or update on
    TOOLBOX_DIRS_REGISTERED
  begin

    -- Invoke the PL/SQL Package procedure simulab_mview.refresh_mview

    simulab_mview.refresh_mview;

  end;

while the PL/SQL Package simulab_mview is defined as follows ;

create or replace
package
simulab_mview
as

    procedure
    refresh_mview;

end;
/

create or replace package body
simulab_mview
as

    procedure
    refresh_mview
    as

    begin

        -- I have a strong suspicion that dbms_mview.refresh might cause a commit to 
        -- be executed. This would make sense, as the RDBMS would need to execute a 
        -- commit so that other clients could see the result of the refresh.

        dbms_mview.refresh('mat_view', 'C');

    end;

end;
/

Does anyone have any thoughts on this? Is there an easier way to do what I want to do, should I not be using Materialized views, should I not be using Triggers?

Any help or even thoughts on this would be immensely appreciated. If anyone is indeed able to provide any help or thoughts on this matter, then I would like to thank them in advance for their assistance.

Have a nice day.

  • 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-09T04:16:34+00:00Added an answer on June 9, 2026 at 4:16 am

    If I am understanding this correctly, I don’t think you want toolbox_dirs_registered to refer to both the users and the user_sessions tables. That isn’t normalized. Only refer to the user_sessions table and you already have a reference to the users table.

    The following snippet is untested and has a lot of cut and paste, but I think it gives the idea:

    CREATE TABLE users(
       user_id  NUMBER
      ,username VARCHAR2(32)
      ,CONSTRAINT users_pk PRIMARY KEY(user_id)
    );
    
    CREATE UNIQUE INDEX users_username_uk ON users(username);
    
    
    CREATE TABLE user_sessions(
       user_session_id NUMBER
      ,user_id         NUMBER
      ,session_id      NUMBER
      ,CONSTRAINT user_sessions_pk PRIMARY KEY(user_session_id)
      ,CONSTRAINT user_session_user_id_fk FOREIGN KEY(user_id) REFERENCES users(user_id)
    );
    
    CREATE UNIQUE INDEX user_sessions_user_session_uk ON user_sessions(user_id, session_id);
    
    
    CREATE TABLE toolbox_dirs_registered(
       dirname         VARCHAR2(100) NOT NULL
      ,user_session_id NUMBER(32)
      ,auto_register   CHAR(1)
      ,CONSTRAINT toolbox_dirs_registered_pk PRIMARY KEY(dirname)
      ,CONSTRAINT tdr_user_session_id_fk FOREIGN KEY(user_session_id) REFERENCES user_sessions(user_session_id)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two databases and 4 tables involved in this query. The first database(PhoneBills)
I am trying to create three tables: Users username userID Categories category categoryID userID
I am trying to define an abstract class that has operators to compare two
I am trying to define nested modules, but I couldn't find any complete explanations
I'm trying to define a new array through a where query but I can
I'm setting up a database using phpMyAdmin. I have two tables ( foo and
I am trying to join two tables. One being the sys.databases table and the
I am trying to write a simple stored proc which takes three arguments 'database
There are database tables in mysql at the backend corresponding to these classes with
I am trying to join two objects, the first is a (static) local object

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.