Home » SQL & PL/SQL » SQL & PL/SQL » I need to process a string with arithmetic operators
I need to process a string with arithmetic operators [message #643688] Thu, 15 October 2015 06:56 Go to next message
spgun
Messages: 1
Registered: October 2015
Junior Member
I have a string (arithmetic_string_ VARCHAR2 (200)) with arithmetic operators so that I need to calculate the final value.
The solution Should give an answer of according to mathematics standards.

My string is as below.
arithmetic_string_: = '10 * 15 / 5-2 ';

The Answer Should be 28 of according to mathematics standards.
Do we have any API for this?

Thanks in advance.
Pradeep.
Re: I need to process a string with arithmetic operators [message #643689 is a reply to message #643688] Thu, 15 October 2015 07:04 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
use execute immediate to dynamically select the result of the expression into a variable from dual.
Re: I need to process a string with arithmetic operators [message #643698 is a reply to message #643688] Thu, 15 October 2015 10:32 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3312
Registered: January 2010
Location: Connecticut, USA
Senior Member
SQL> select xmlquery(replace('10 * 15 / 5-2 ','/','div') returning content)
  2    from dual
  3  /

XMLQUERY(REPLACE('10*15/5-2','/','DIV')RETURNINGCONTENT)
--------------------------------------------------------------------------------
28

SQL> select dbms_aw.eval_number('10 * 15 / 5-2 ')
  2    from dual
  3  /

DBMS_AW.EVAL_NUMBER('10*15/5-2')
--------------------------------
                              28

SQL> 


SY.
Re: I need to process a string with arithmetic operators [message #643700 is a reply to message #643698] Thu, 15 October 2015 11:44 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
test>select 10 * 15 / 5-2 from dual;

10*15/5-2
----------
28

test>
Previous Topic: split data with levels
Next Topic: binary to hexadecimal conversion
Goto Forum:
  


Current Time: Mon Jul 13 13:53:49 CDT 2026