Dynamic Sql in SP

Database
N/A

Dynamic Sql in SP

Please check the underlined sql and let me know whether it requires prepare statement and Execute statement or Execute Immedietly statement.

For the Cursor SQL I used prepare statement  i am not sure for the underlined part. Those variables in sql are either input variables or variable which got value from  the previous blocks in the same proc. Your help is appreciated

Declare c_CDC_FIELDS CURSOR  FOR S3

SET SqlStr2  ='Select   FLDTB.FLD_TYP_ID   From ETL_IH_CNF_EVNT_TYP_USG_FLD          FLDTBL      

WHERE  FLDTBl . ID_IND ='N' AND FLDTBL .IH_CNF_EVNT_TYP_USG_ID = V_Update Usage_id ‘

PREPARE S3 FROM SqlStr2

Open c_CDC_FIELDS;

LOOPL3:LOOP

Fetch c_CDC_FIELDS INTO v_CDC_VAR;

IF SQLSTATE <> '00000' THEN LEAVE LOOPL3;

SET SqlStr3  =’Select    V_update_FLDTYPID       from V_WRKTBLNAME_IN

Inner join  V_BASETBLNAME_IN

on V_WRKTBLNAME_IN.V_update_FLDTYPID       =V_BASETBLNAME_IN. V_update_FLDTYPID      

and V_BASETBLNAME_IN. end_dt = High date

and V_WRKTBLNAME_IN. CDC_VAR <>V_BASETBLNAME_IN. CDC_VAR.

Into  UPDT_KY_VAR’

Prepare S4 from  SqlStr3

Execute S4

If UPDT_KY_VAR <> blank

Then

ITERATE LOOPL3;