Results 1 to 5 of 5
  1. #1
    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.

  2. #2
    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.

  3. #3
    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.

  4. #4
    Join Date
    Nov 2003
    Posts
    87
    ThnQ Very Much.

  5. #5
    Join Date
    Dec 2003
    Posts
    11
    thnx for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •