If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > How do we execute a string in PL/SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Dec 2003
Posts: 11
How do we execute a string in PL/SQL

Can someone tell me that how can we execute a variable in PL/SQL that has some formula in it...

for example

lv_formula VARCHAR2(10):='(34+5)*8';


i want to execute the lv_formula so it gives 312.
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Nov 2003
Posts: 87
I think, u cant execute that directly.

You can do it by extracting the numbers from that string seperately and operators also, store it into an array, then take one by one and calculate.
Reply With Quote
  #3 (permalink)  
Old
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: How do we execute a string in PL/SQL

Use dynamic PL/SQL:

SQL> DECLARE
2 lv_formula VARCHAR2(10):='(34+5)*8';
3 result NUMBER;
4 BEGIN
5 EXECUTE IMMEDIATE 'BEGIN :out := '||lv_formula||'; END;' USING OUT result;
6 DBMS_OUTPUT.PUT_LINE('Answer is...' || result);
7 END;
8> /
Answer is...312

PL/SQL procedure successfully completed.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Nov 2003
Posts: 87
ThnQ Very Much.
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Dec 2003
Posts: 11
thnx for the help
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On