I need to get transaction_dates in transactions table to write on a column in a table named payment_plan. But i need to do this operation just for polices that has payment_method as directdebit and cash . So i built follwing query;
MERGE INTO PAYMENT_PLAN pp
USING
(
SELECT pt.transaction_date
FROM payment_plan pp
JOIN transactions pt ON (pp.transaction_id = pt.transaction_id)
JOIN policy pol ON (PP.POLICY_ID = POL.POLICY_ID)
WHERE pp.payment_plan_status = 'CLOSED'
AND POL.PAYMENT_METHOD IN ('Cash','DirectDebit')
AND pp.bank_clearance_date IS NULL
AND pp.transaction_id IS NOT NULL
AND pt.transaction_date IS NOT NULL
) ta ON (ta.transaction_id = pp.transaction_id)
WHEN MATCHED THEN UPDATE
SET pp.bank_clearance_date = ta.transaction_date,
pp.effective_date = ta.transaction_date,
ta.receipt_date = ta.transaction_date;
It gets an " ORA-00904: "TA"."TRANSACTION_ID": Invalid Identifier" error.
So, how can i get transaction_date columns of cash and direct_debit policies?
In the query in the
USINGclause you onlySELECT pt.transaction_dateand do not includetransaction_idso the identifier is unknown. If you want to use that column then you have to include it in theSELECTclause.However, if you want to update the same row then you can use the
ROWIDpseudo-column (which is effectively a pointer to the row):or you could simplify the query to: