The AskTOM team is taking a break over the holiday season, so we're not taking questions or responding to comments. Please have a happy and safe festive season and as always, thanks for being a member of the AskTOM community.
Thanks for the question, AnoopSagar.
Asked: April 15, 2010 - 2:00 am UTC
Last updated: April 16, 2010 - 10:04 am UTC
Version: 8.0.6.0.0
Viewed 10K+ times! This question is
Sokrates, April 16, 2010 - 1:49 am UTC
sql > select * from v$version where rownum=1; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production sql > create function 2 eval_simple_arithmetic_expr(vexpr in varchar2) 3 return number 4 is 5 evaluated number; 6 begin 7 select 8 xmlquery( 9 replace( vexpr, '/', ' div ') 10 returning content 11 ).getNumberVal() 12 into evaluated 13 from 14 dual; 15 return evaluated; 16 end eval_simple_arithmetic_expr; 17 / Function created. sql > select eval_simple_arithmetic_expr('5/100*300'), 5/100*300 from dual; EVAL_SIMPLE_ARITHMETIC_EXPR('5/100*300') 5/100*300 ---------------------------------------- ---------- 15 15 sql > select eval_simple_arithmetic_expr('1*2*3+4+5*6+7'), 1*2*3+4+5*6+7 from dual; EVAL_SIMPLE_ARITHMETIC_EXPR('1*2*3+4+5*6+7') 1*2*3+4+5*6+7 -------------------------------------------- ------------- 47 47 sql > select eval_simple_arithmetic_expr('193 mod 47'), mod(193, 47) from dual; EVAL_SIMPLE_ARITHMETIC_EXPR('193MOD47') MOD(193,47) --------------------------------------- ----------- 5 5
Anoop, April 19, 2010 - 3:24 am UTC
More on PL/SQL routine DBMS_SQL here