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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

SQL Query-Incremental data logic

Neils KhJul 22 2024

I have source and staging tables & target table, I want to bring in incremental data into staging from source.

I have 2 date columnCreatedDate and UpdatedDate to work with to bring in the incremental data in stage

Table structure (ID_Pk, CreatedDate, UpdatedDate)

CreatedDate and UpdatedDate are date with time stamp and ID is PK

e.g. Created Date/updated date format ‘2024-05-09 16:13.03.5722250’

I have to write SQL to get only incremental data from source table, by using UpdateDate if not null, in case if updated date is null then use CreateDate to pull the incremental data.

I got the vmaxCreatedDate and vmaxUpdatedDate from targate table put it into varaibles and wrote below query, question is this this sql correct for incremental data load. I am inform to pick incremental data using UpdateDate in case it is NULL then use CreatedDate to bring in only incremental data

Select * from SourceTbl where updateDate > vmaxUpdatedDate  and updateDate  is not null
UNION
Select  * from SourceTbl where createdDate > vmaxCreatedDate 
This post has been answered by JonWat on Jul 23 2024
Jump to Answer
Comments
Post Details
Added on Jul 22 2024
6 comments
1,189 views