Variable Substitution, Execute Formula
Hi,
I want to calculate some numericals on a stored formula in the table. The scenario is as follows:
Declare
ll_val1 number(5) := 25;
ll_val2 number(5) := 50;
ll_formula varchar2(100) := 'll_val1 + ll_val2';
Begin
/* Pls help me writing a script which will print a output called 75 on executing the ll_formula variable i.e., i want to execute the formula variable(ll_formula) and display the result as '75' */
print the value 75 was per the variable.
End ;
Variable Substitution, Execute Formula (Solved)
Hi DaPi,
Thanks for your valueable input, i was able to solve the problem i posted.
Here is the code which made this happened:
CREATE OR REPLACE PROCEDURE P_DYNAMICFORMULA
( ll_formula char )
is
ll_val1 number(5) := 25;
ll_val2 number(5) := 50;
ll_result number(5);
begin
EXECUTE IMMEDIATE ('SELECT ' || REPLACE(ll_formula,'ll_val',':a') || ' FROM DUAL') INTO ll_result USING IN ll_val1, IN ll_val2;
dbms_output.put_line('result : ' || ll_result );
end P_TESTDYNAMICFORMULA;
SQL> exec P_DYNAMICFORMULA('ll_val1+ll_val2')
result : 75
PL/SQL procedure successfully completed.
SQL> exec P_DYNAMICFORMULA('ll_val1-ll_val2')
result : -25
PL/SQL procedure successfully completed.
SQL> exec P_DYNAMICFORMULA('ll_val1*ll_val2')
result : 1250
Thanks again...