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!

Query help to insert record in target table

Ricky007Apr 27 2020 — edited May 5 2020

Hi experts,

Please help

create table source_table

(

S_HIGH_RANGE VARCHAR2(20),

S_LOW_RANGE VARCHAR2(20),

S_NAME VARCHAR2(20),

S_PUK_CODE VARCHAR2(20)

);

INSERT INTO source_table VALUES('987654','123456','JOHN','2005');

INSERT INTO source_table VALUES('965214','852149','JAMES','3115');

INSERT INTO source_table VALUES('935478','532145','JACOB','5248');

COMMIT;

create table Target_table

(

T_HIGH_RANGE VARCHAR2(20),

T_LOW_RANGE VARCHAR2(20),

T_NAME VARCHAR2(20),

T_PUK_CODE VARCHAR2(20)

);

INSERT INTO Target_table VALUES('987654','123456','JOHN','2005');

INSERT INTO Target_table VALUES('965214','852149','JAMES','3005');

COMMIT;

Here I want to check all 4 fields  from source table if the value is not available then insert the value in target table

else,if any one field value mismatching then update the recent values available in source table

For T_low_range need to have digit should be append as 0

Here I want to check all 4 fields  from source table if the value is not available then insert the value in target table

else,if any one field value mismatching then update the recent values available in source table

For T_low_range need to have digit should be append as 0

Expected Result

Select * from Target_table;

T_HIGH_RANGE                  T_LOW_RANGE              T_NAME               T_PUK_CODE

987654                                  1234560000                             JOHN              2005     --- append 0

965214                                  8521490000                            JAMES             3115     -- Puk code mismatch

935478                                  5321450000                          JACOB              5248     -- new record

Please help

Comments
Post Details
Added on Apr 27 2020
6 comments
303 views