I am writing a stored procedure using oracle. I am new to oracle, and stored procedures, but what I am trying to do seems fairly straight forward, yet I am having trouble.
I have 2 tables BATCH_ISA
and BATCH_TEMP
the temp table was created with records from the BATCH_ISA
as well as a few other tables. I need to update a flag in the BATCH_ISA
table from 'Y' to 'N' after the records have been successfully moved into the BATCH_TEMP
table.
I am trying to do an update for all the the records in BATCH_ISA
where the ISA_KEY
field is found in both of the tables, and setting the flag to 'N'
What is the basic update statement I should use?
-- SET EVERYTHING TO 'N' FIRST:
UPDATE BATCH_ISA
SET
FLAG = 'N';
-- NOW UPDATE ONLY MATCHED ROWS TO 'Y':
UPDATE BATCH_ISA
SET
FLAG = 'Y'
WHERE
EXISTS (
SELECT * FROM BATCH_TEMP
WHERE BATCH_ISA.ISA_KEY = BATCH_TEMP.ISA_KEY
);
COMMIT;
I removed the commit after the first update, but if there are plenty of rows you could use it to save redolog overhead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.