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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:28:58+00:00 2026-06-14T16:28:58+00:00

I have a start_session and end_session. I want to make sure with a constraint

  • 0

I have a start_session and end_session.

I want to make sure with a constraint that the end_session is 60 minutes after the start_session.

Is this possible, something like the following

ALTER TABLE BOOKING_SESSION ADD CONSTRAINT SESSION_LENGHT CHECK (END_SESSION > START_SESSION + 60 MINUTES );

I got the following trigger to check that the start session is not bigger than the end session (thanks to Justin Cave)

CREATE OR REPLACE TRIGGER trg_check_dates
  BEFORE INSERT OR UPDATE ON BOOKING_SESSION
  FOR EACH ROW
BEGIN
  IF( :NEW.END_SESSION < :NEW.START_SESSION )
  THEN
    RAISE_APPLICATION_ERROR( -20001, 
          'Invalid: END_SESSION must be greater than START_SESSION = ' || 
          to_char( :NEW.START_SESSION, 'YYYY-MM-DD HH24:MI:SS' ));
  END IF;
 END;
 /

However i need the one that makes sure that the end session is one hour after the start_session

  • 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-14T16:29:01+00:00Added an answer on June 14, 2026 at 4:29 pm

    Here is how the Check constraint can be used to impose that kind of restriction:

    SQL> create table Tb_test(
      2    id number not null primary key,
      3    start_session timestamp,
      4    end_session   timestamp
      5  )
      6  ;
    
    Table created
    
    SQL> 
    SQL> alter table tb_test
      2    add constraint CHK_SES_TIME
      3  check ((end_session is null) or ((end_session - start_session) >= interval '1' hour))
      4  ;
    
    Table altered
    
    -- data that is violate our constraint
    SQL> insert into tb_test(id, start_session, end_session)
      2    values(1, systimestamp, systimestamp)
      3  ;
    
    insert into tb_test(id, start_session, end_session)
      values(1, systimestamp, systimestamp)
    
    ORA-02290: check constraint (HR.CHK_SES_TIME) violated
    
    -- valid data 
    SQL> insert into tb_test(id, start_session, end_session)
      2    values(1, systimestamp, systimestamp + interval '1' hour)
      3  ;
    
    1 row inserted 
    
    -- only start session added, end_session is null.
    SQL> insert into tb_test(id, start_session)
      2    values(2, systimestamp)
      3  ;
    
    1 row inserted
    
    SQL> commit;
    
    Commit complete
    
    -- updating end_session with data that violate check constraint
    SQL> update tb_test
      2    set end_session = systimestamp;
    
    update tb_test
      set end_session = systimestamp
    
    ORA-02290: check constraint (HR.CHK_SES_TIME) violated
    
    -- updating end_session with valid data
    
    
    SQL> update tb_test
      2    set end_session = systimestamp + interval '1' hour;
    
     1 row updated
    

    In the example above start_session and end_session columns are of timestamp datatype. If you have them declared as Date datatype then formula for the check constraint might be:

    (end_session - srtart_session) >= 1/24  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two php scripts remove_directory.php <?php start_session(); $userId = $_SESSION['userId']; exec(escapeshellcmd(rm
I have an events based table that I would like to produce a query,
I want to have a comet-like iframe on my page, but when the session
I have a trigger that I want to run before insert a row into
I have the following code (just as a test) and I want to create
I'm sure that this question has already been asked, but I don't really see
First, I have a stateless bean which do a simple retreive, looking like this.
I have a header.html which start with session_start();. Then the following code, $_SESSION['cart'][$sw_id] is
I have the following code: while ($content = mysql_fetch_array($content2)){ echo $content[0]; session_start(); $_SESSION['content'] =
I have the following pages: page1.php <?php if (isset($_GET['link'])) { session_start(); $_session['myvariable'] = 'Hello

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.