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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:13:51+00:00 2026-06-08T21:13:51+00:00

I have a table called as Activity with columns like activity_id and activity_date .

  • 0

I have a table called as Activity with columns like activity_id and activity_date.

Consider a data in activity table like below,

activity_id    activity_date    
1              1st June
2              1st July
3              1st August
4              1st September
5              1st October

Now I want to change the date of the activity 3, but I can not change the date to less than 1st July or more than 1st September as there are already some other activities on those dates.

The only valid dates for activity 3 are between 2nd July to 30th August.

Similarly, for activity 1, valid new date can be any date before 1st July.

Similarly, for activity 5, valid new date ranges from 2nd September to any date in future as its last activity.

I need to give the validation message to the user in front end if the new date is not within the range.
Input to the query will be activity id and the new activity date.

Below is the DDL script

    CREATE TABLE "HEADCOUNT"."ACTIVITY" 
(   "ACTIVITY_ID" NUMBER(*,0) NOT NULL, 
    "ACTIVITY_DATE" DATE
); 

Insert into "HEADCOUNT"."ACTIVITY" (ACTIVITY_ID,ACTIVITY_DATE) values (1,'01-06-2012');
Insert into "HEADCOUNT"."ACTIVITY" (ACTIVITY_ID,ACTIVITY_DATE) values (2,'01-07-2012');
Insert into "HEADCOUNT"."ACTIVITY" (ACTIVITY_ID,ACTIVITY_DATE) values (3,'01-08-2012');
Insert into "HEADCOUNT"."ACTIVITY" (ACTIVITY_ID,ACTIVITY_DATE) values (4,'01-09-2012');
Insert into "HEADCOUNT"."ACTIVITY" (ACTIVITY_ID,ACTIVITY_DATE) values (5,'01-10-2012');
  • 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-08T21:13:53+00:00Added an answer on June 8, 2026 at 9:13 pm

    This will find the date ranges for each row:

    SELECT activity_id, activity_date
          ,NVL( LAG(activity_date) OVER(ORDER BY activity_id) 
               ,TO_DATE('1900-01-01', 'YYYY-MM-DD')
              ) AS previous_date
          ,NVL( LEAD(activity_date) OVER(ORDER BY activity_id)
               ,TO_DATE('2100-01-01', 'YYYY-MM-DD')
              ) AS next_date
      FROM activity
      ORDER BY activity_id
    

    Result:

                           ACTIVITY_ID ACTIVITY_DATE PREVIOUS_DATE NEXT_DATE
    ---------------------------------- ------------- ------------- ---------
                                     1 01-JUN-12     01-JAN-00     01-JUL-12 
                                     2 01-JUL-12     01-JUN-12     01-AUG-12 
                                     3 01-AUG-12     01-JUL-12     01-SEP-12 
                                     4 01-SEP-12     01-AUG-12     01-OCT-12 
                                     5 01-OCT-12     01-SEP-12     01-JAN-00
    

    Validation would then be for a given id:

    “input date” > previous_date AND “input date” < next_date

    Date ranges are based on previous and following records when ordered by activity_id. Perhaps the ordering should really be by activity_date, though. Using LAG and LEAD will allow for gaps in activity_ids as well.

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

Sidebar

Related Questions

I have a table called activity that uses the following columns: LoginDate, LoginID, Department,
I have a table called 'MyTable' that looks like: ID | Item | Type
I have a table called sellerparams with a number of columns, one of them
I have a table called 'main_table' with 3 columns : 'player', 'points' and 'drop_date'
I have a table called Activities and for each activity I can have zero
I have table called stats . In am inserting yes or no in the
i have table called as Support, which have a field named Name and contains
I have table called Buttons. Buttons table i have column button_number . Table contain
I have table called posts in my DB. Each post has field called social_network
I have a table called States and i am displaying values of states in

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.