Reputation: 57
I have a task to create a stored procedure in Oracle DB. Given two different databases DB1 with student_lookup table and DB2 with student_master table . The SP needs to check if DB2.student_master's record exists in DB1.student_lookup table.
Any help will be appreciated. I am completely new to Oracle DBA.
Upvotes: 1
Views: 261
Reputation: 665
If it's two users using:
MERGE INTO db1.student_lookup a
USING
(select * from db2.student_mater) b
ON (
a.id = b.id
AND <others join column>
)
WHEN MATCHED THEN UPDATE SET a.partition_key = 1
WHEN NOT MATCHED THEN INSERT (<a.column>)
VALUES (<b.column>)
If it's two db:
CREATE DATABASE LINK DBLINK_DB1_DB2
CONNECT TO DB2 IDENTIFIED BY <ENTER USER PASSWORD HERE>
USING '<FROM tnsnames>'
MERGE INTO db1.student_lookup a
USING
(select * from "student_mater"@"DBLINK_DB1_DB2") b
ON (
a.id = b.id
AND <others join column>
)
WHEN MATCHED THEN UPDATE SET a.partition_key = 1
WHEN NOT MATCHED THEN INSERT (<a.column>)
VALUES (<b.column>)
If you neen SP simple megre into your SP.
Upvotes: 1