Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluating a string

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello!

I want to know if you can "evaluate" a string in Oracle-SQL. I want "2+4+5+1" to be calculated
into "12".

Thanks

/Fredrik M
 
Hi this is quite easy just skip the quotes!


create table test (lit varchar2(20));

insert into test (lit) values (2+4+5+1); => Results in a value of lit='12'

insert into test (lit) values ('2+4+5+1'); => Results in a
value of lit=''2+4+5+1'

that's it
 
Thats not what I was looking for.
Im going to use this to calculate a couple of thousand formulas, the problem is that i have 1500 different formulas,
Example:
Formula "((2000/12)*(x/123))*1,2)"

I get this formula from a table and replace x with a number:
Answer = "((2000/12)*(143.55/123))*1,2)"

/Fredrik M
 
declare
result number;
expression varchar2(100) := '1+2';
begin
execute immediate 'begin :1 := '||expression||'; end;' using out result;

end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top