Discussion Locked

Oracle Database - Dynamic SQL

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I want ot be able to store a formula as a string in the database and then
apply it to calculate a price.

The problem I'm having is that Oracle does not seem to recognise the + * /
or - operators when in a char string.
Example
Char string(3 * 30) / (2*5) returns ' (3 * 30) / (2*5)' and not 9

Can anyone help me solve this problem?

4 replies

by snowman_mtu

You can use native dynamic SQL (Oracle 8.1.6).
Example:
1. Yours formulas stored in table FORMULA_TAB (rule varchar2(50))
2. This code is calculate yours formulas:

declare
sRule varchar2(50);
nResult number;
begin
select rule into sRule from formula_tab where rownum <= 1; (or any other criteria :-))
execute immediate 'select ' || sRule || ' from dual' into nResult;
dbms_output.put_line(to_char(nResult));
end;

You can reorganize this code to stored function and then executeit.

by jenni

Your help is much appreciated. I had tried this option, but I had my quotes in the wrong place.

This discussion is closed to new replies.