I have a table A
, where there is a column D_DATE
with value in the form YYYYMMDD
(I am not bothered about the date format). I also happen to have another table B, where there is a column name V_TILL
. Now, I want to update the V_TILL column value of table B with the value of D_DATE
column in table A
which happens to have duplicates as well. Meaning, the inner query can return multiple records from where I form a query to update the table.
I currently have this query written but it throws the error:
ORA-01427: single-row subquery returns more than one row
UPDATE TAB_A t1
SET (V_TILL) = (SELECT TO_DATE(t2.D_DATE,'YYYYMMDD')
FROM B t2
WHERE t1.BR_CODE = t2.BR_CODE
AND t1.BK_CODE = t2.BK_CODE||t2.BR_CODE)
WHERE EXISTS (
SELECT 1
FROM TAB_B t2
WHERE t1.BR_CODE = t2.BR_CODE
AND t1.BK_CODE = t2.BK_CODE||t2.BR_CODE)
PS: BK_CODE
IS THE CONCATENATION OF BK_CODE
and BR_CODE
Kindly help me as I am stuck in this quagmire! Any help would be appreciated.
SELECT TO_DATE(t2.D_DATE,'YYYYMMDD') FROM B t2 WHERE t1.BR_CODE = t2.BR_CODE AND t1.BK_CODE = t2.BK_CODE||t2.BR_CODE
You should add some condition – Ersin Gülbahar