ORA-01007: variable not in select list
Oracle hurls ORA-01007
when the columns of our query don't match the target variable.
Line 53 is this line FETCH c2 INTO De_Dub_rec;
, so the clue is the projection of the cursor doesn't match the record type.
Your free-text SELECT statement is messily laid out, which makes debugging hard. Let's tidy up the projection:
SELECT S.TRANS_GUID AS OLD_TRANS_GUID
, S.DETL_CLMNS_HASH AS DETL_CLMNS_HASH1
, S.KEY_CLMNS_HASH AS KEY_CLMNS_HASH1
, S.RX_DSPNSD_DT AS R_DSPNSD_DT
, S.SUPPLIER_PHARMACY_CD AS SUPPLIER_PHARMACY_CD1
FROM ...
Now it becomes easy to see that the column order is different from the type's attribute order:
TYPE rec_typ IS RECORD
(
OLD_TRANS_GUID VARCHAR2 (255),
R_DSPNSD_DT DATE,
DETL_CLMNS_HASH1 VARCHAR2(255),
KEY_CLMNS_HASH1 VARCHAR2(255),
SUPPLIER_PHARMACY_CD1 VARCHAR2(200)
);
So your code is trying to put a string into a date variable (and vice versa, but at least Oracle can cast that).
All of which goes to prove that clear layout is not a silly OCD thing. Discipline in writing code helps us write better code quicker by highlighting obvious errors.