简体   繁体   中英

How can I convert a string into a math expression in Oracle SQL?

I am trying to write an Oracle SQL query that can take a dynamically-generated string and convert it to a mathematical expression, for example: '1*2*1*3*2' would evaluate to 12.

I have done Google searches, but the only Oracle-specific examples I can find are ones that require using a PL/SQL Stored Function. That isn't an option for me, because I do not have 'CREATE' privileges on my organization's production database. Since I often need to troubleshoot SQL code against the production DB, I avoid using Stored Procedures or Stored Functions in my report development tool (LogiInfo).

So...what I am hoping to find is some type of 'built-in' function I can place directly into an SQL statement, that will perform the conversion and evaluation described in my opening sentence. Any guidance will be appreciated.

PS I am using Oracle 11g

If you can use SQLPLus you can execute anonymous plsql blocks of code.

Example:

set serveroutput on

declare
   i pls_integer;
begin
   execute immediate 'select 1*2*1*3*2 from dual'
      into i;
   dbms_output.put_line(i);
end;
/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM