I want to optimize a select query in a loop of a SQL procedure. The loop iterates around 10000 times and the select query takes approx. 30 ms for each iteration which increases the overall execution time of the procedure
SELECT *
FROM BANKACCOUNTS B,
MAPPING M,
UPL_DTR_UPLOAD UP,
(SELECT * FROM MAPPING WHERE SOURCE = 'KARVY_BANK_CODE') M1
WHERE B.SCHEME_CODE = M.INTERNALCODE
AND M1.INTERNALCODE = B.BANK_CODE
AND M.SOURCE = 'R0'
AND B.AC_TYPE = 'FUNDING'
AND M.EXTERNALCODE IS NOT NULL
AND UPPER(TRIM(M.EXTERNALCODE || M1.EXTERNALCODE || B.AC_NO)) =
Upper(UP.Scheme || UP.Fundingbnk || UP.fundingacc);
JOINsyntax. Easier to write (without errors), easier to read (and maintain), and easier to convert to outer join if needed.