Execute Immediate for an IF statement
VinaySep 16 2009 — edited Sep 17 2009All,
I am trying to execute an IF statement dynamically at run time using Execute Immediate statement but I am gettign errors.. The error is PLS-00201: identifier 'V_BARG_UNIT' must be declared
The condition and the result for the if statement is stored in a table test_dynamic_if_tbl which has 2 columns.
condition = v_barg_unit='ABC' and result_val = v_bg_group := '93'
Hereis the code..
DECLARE
cmd VARCHAR2 (4000);
v_barg_unit VARCHAR2 (10) := 'ABC';
v_bg_group VARCHAR2 (10) := ' ';
CURSOR abc
IS
SELECT * FROM test_dynamic_if_tbl;
BEGIN
FOR c1 IN abc
LOOP
cmd :=
'Begin
If ' || c1.condition
|| ' THEN '
|| c1.result_val
|| ' ; End if;
End;';
DBMS_OUTPUT.put_line ('cmd: ' || cmd);
EXECUTE IMMEDIATE cmd ;
DBMS_OUTPUT.put_line ('Condition: ' || c1.condition);
DBMS_OUTPUT.put_line ('result_value: ' || c1.result_val);
DBMS_OUTPUT.put_line ('v_bg_group: ' || v_bg_group);
END LOOP;
END;
What am I doing wrong?
Thanks for your help in advance,
Vinay
Edited by: user652279 on Sep 16, 2009 11:45 AM
Edited by: user652279 on Sep 16, 2009 11:47 AM