Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6220173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:54:44+00:00 2026-05-24T07:54:44+00:00

I’m a newbie in PLSQL. I was just wondering if I can save my

  • 0

I’m a newbie in PLSQL. I was just wondering if I can save my formula into a table as string and use it in my functions to calculate some values.

Here is an example:

ID         NAME          FORMULA
1          test          prm_testval*prm_percent/18
2          test2         (prm_testval +20)*prm_percent

what I want to do is to select formula column from the table and use the string in my functions

select t.* from table t where id=1

prm_calculated_value = t.formula 

I don’t want the string value of formula in here, just the formula itself.

Any ideas, If I can use it or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:54:45+00:00Added an answer on May 24, 2026 at 7:54 am

    The starting point is execute immediate-statement. It’s PL/SQL’s eval().

    create table formulas (
      id number,
      name varchar2(20),
      formula varchar2(50)
    );
    
    insert into formulas values (1, 'test 1', 'prm_testval*prm_percent/18');
    insert into formulas values (2, 'test 2', '(prm_testval +20)*prm_percent');
    
    /* eval from: http://www.adp-gmbh.ch/blog/2005/may/5.html */
    create or replace function eval (
     expr in varchar2
    ) return varchar2 as 
      ret varchar2(32767);
    begin
      execute immediate 'begin :result := ' || expr || '; end;' using out ret;
      return ret;
    end;
    /
    
    create or replace function eval2 (
      vars in varchar2,
      expr in varchar2
    ) return varchar2 as 
      ret varchar2(32767);
    begin
      execute immediate vars || ' begin :result := ' || expr || '; end;' using out ret;
      return ret;
    end;
    /
    
    create or replace function calc_prm (
      id_ in number,
      prm_testval in varchar2, 
      prm_percent in varchar2
    ) return number as
      formula_ formulas.formula%type;
      vars constant varchar2(32767) := 
        'declare prm_testval constant number := to_number(' || prm_testval ||
        '); prm_percent constant number := to_number(' || prm_percent || ');';
    begin
      select formula into formula_ from formulas where id = id_;
      return eval2(vars, formula_);
    end;
    /
    
    /* call from SQL */
    select eval('3*4') from dual;
    select calc_prm(1, 97, 10) from dual;
    select calc_prm(2, 97, 10) from dual;
    
    /* call from PL/SQL block */
    begin
      dbms_output.put_line(eval('3*4'));
      dbms_output.put_line(calc_prm(1, 97, 10));
      dbms_output.put_line(calc_prm(2, 97, 10));
    end;
    /
    

    Based on this example you can start building your own way to map symbol values (prm_testval and prm_percent) to real values. Next you might want to have a look into DBMS_SQL.

    Beware SQL injection when using client supplied data ! See also e.g. Bobby Tables: A guide to preventing SQL injection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.