Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to do this complex date comparison?

Ora Dev SgJan 12 2017 — edited Jan 13 2017

I need to create a SQL to retrieve some value.  The SQL has many joins, but there is a date comparison to do also.

In this system, an child-statement belongs to a master-statement.

However, the master-statement has a date range.

The child-statement also has a date range.

So, we need to get information for the child-statement which belongs to the date-range of the master-statement.

How can we create the WHERE-CLAUSE because there can be about 4 or 5 situations.

Is it good practice to do something like this:

SELECT *

FROM tables

WHERE

   conditons AND

   date_range_check(ms.start_date, ms.end_date, cs.start_date, cs_end_date) = 'TRUE';

DATE_RANGE_CHECK is a function which returns a TRUE or FALSE value and is defined in the same SP in the declare section.

Will this have a performance impact?

Also, how do check the dates since there could be many possibilities?

Like

                                                        ms.start_date <--------------------------------------------------------------->ms.end_date

(1.)                                                                                           cs.start_date<-------->cs.end_date

(2.)                  cs.start_date<------------------------------------------>cs.end_date

(3.)                                                                                                            cs.start_date <--------------------------------------------->cs.end_date

(4.)                   cs.start_date<---------------------------------------------------------------------------------------------------------------------->cs.end_date

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 10 2017
Added on Jan 12 2017
23 comments
1,080 views