Dynamically how to calculate expression through PL/SQL ..?

My senario like...
I want to calculate the expression using array values from input parameter and then I want to send that calculated values as a output parameter.
How to do through PL/SQL..?
I am passing two parameter.
1. expression variable value as array,
2. expression as string
I want to execute that expression using Execute immediate or any other way through PL/SQL.
For Example,
exec myPL_SQLproc(p1,p2)
p1,p2 = (1,2,3), 'a*(a+10)-b+c'
p1,p2 = (1,2,3,4,5), '((a+b+c+d+e)+(a-b-c-d-e))*log(a)' here base10 for log(a).
here p1 is array (pl/sql table type)
p2 is string (expression: varchar2 type)

Although I think this is likely to be a bad design decision, you can use something like:
DECLARE
   TYPE values_tp IS VARRAY(10) OF NUMBER;
   l_values_tp values_tp := values_tp(1,2,3);
   l_expr VARCHAR2(25) := 'a*(a+10)-b+c';
   l_exec VARCHAR2(25);
   l_result NUMBER;
BEGIN
   FOR i IN 1 .. l_values_tp.COUNT LOOP
      l_expr := REPLACE(l_expr, CHR(96+i), l_values_tp(i));
   END LOOP;
   DBMS_OUTPUT.Put_Line(l_expr);
   EXECUTE IMMEDIATE 'SELECT '||l_expr||' FROM dual' INTO l_result;
   DBMS_OUTPUT.Put_Line('Result is '||l_result);
END;Minimally, you should check the formula string for things like semi-colons (;) and two consecutive hyphen (--) which could indicate a sql injection attempt. You would also probably need much more error handling.
TTFN
John

Similar Messages

  • How to calculate XOR in pl/sql

    could you please tell me how to calculate XOR in pl/sql?

    Here are some examples
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1284001741333

  • How to create folders through PL/SQL  -  Urgent Please

    Hi,
    We are using Oracle 9i on Windows NT. Is there any way to create a folder in a specified directory through PL/SQL?
    Thank you.

    Well,
    You can and you can't. I don't know how to do that through existing PL/SQL utilities. But, you can create your own utility using java, and wrapping it so you can call it from PL/SQL.
    An example of calling Operating System commands can be found in this zip file
    http://www.ckamco.com/Execute_Command.zip
    Please let me know if this helps at all.
    Thanks
    TwoPigs

  • How To Create User through Pl SQL Block

    Want to create user from pl sql block using dynamic SQl. Used dbms_sql package . But when I run the block it does not recognises the parameter v7 which is a constant in dbms_sql package. Message displayed is Can not access parameter from package being restricted procedure.
    Is there any method to create user through PL SQl block

    hi ranjit,
    hope this will work
    declare
    uname varchar2(30):=&uname;
    pword varchar2(30):=&pword;
    begin
    execute immediate ('grant connect, resource to '| |uname| |' identified by '| |pword);
    end;
    regards

  • How to calculate HASH_VALUE for Specific SQL

    I have an auditing trigger and want to filter out known statements.
    I can, from within the trigger, obtain the SQL that fired the trigger (dbms_standard.sql_txt function).
    I want to be able to calculate the HASH_VALUE for this SQL to use in a decision tree.
    If I have auditing enabled (I do) I can use the audsid {sys_context('USERENV','SESSIONID')} to lookup my SID and from there peruse several V$ views. This seems rather cumbersome.
    Does anyone know of a built-in function to either calculate the HASH_VALUE, when given SQL_TEXT or to return the HASH_VALUE for the firing SQL statement?
    Thanks

    Hi,
    SQL> select count(1) from user_tables;
      COUNT(1)
         21805
    SQL> select hash_value,sql_text
      2  from v$sqlarea
      3  WHERE sql_text LIKE 'select count(1) from user_tables%';
    HASH_VALUE
    SQL_TEXT
    2802460921
    select count(1) from user_tables
    SQL> Nicolas.

  • How to calculate bandwidth through Multi-bitrate player

    Hello everyone
    I want to create multi-bitrate player to play VOD and Live stream.
    Now for switch between each video bitrate I have to find currently bandwidth between AMS server and client player.
    For get current bytes per second I use netstream info but this not stable to decision for switch between bitrates, also I use netConnection checkBandwidth for get the current bandwidth between client-server and sum this value with current bytes persecond for calculate current bandwidth between them but this values is not stable to decision.
    Please advise me to fix this problem.
    Thanks in advance.

    if the bandwidth is not stable between client and server then "it is not stable" not matter what tool you use to measure...What is your specific question?
    The server supplied checkbandwdth method is better way to find out bandwidth and is being used by other customers too to make a switch in case of MBR(Multi Bit Rate).

  • How to calculate IO on SQL Query.

    Hi all,
    Could u please tell me how to calculate IO for specific SQL Query.
    Regards,
    Santosh.

    In what context you are looking the IO consumed for the query? One option you have got is Autotrace,another can be tracing the query and formatting the results using Tkprof.
    Aman....

  • How to modify stored procedures in SQL Azure database in SQL server express 2012

    Hi,
    I want to modify stored procedures in SQL Azure database in SQL Server Express 2012. But when right click on the stored procedure in Object Explorer, there is no option "Modify" as for SQL Server database. I wonder how to modify stored procedures in SQL
    Azure database in SQL Server Express 2012. Thanks.
    York

    Hi,
    Not sure whay there is no modify..
    As a workaround can you try this and see if you can modify proc..
    Script Procedure As-> Alter To->New query window..
    - Chintak (My Blog)

  • How to import *.dmp file Through Oracle SQL Developer (3.2.20.09)

    hi
    how to import *.dmp file Through Oracle SQL Developer (3.2.20.09) ?
    how to do it ?
    thanks

    You do not.
    .dmp files are created from our Export and Data Pump database utilities and are proprietary files. You use the corresponding Import (or Data Pump) utility to import the data.

  • How i can load excel sheet into a table in oracle through pl/sql procedure

    Hi,
    How i can load excel sheet into a table in oracle through pl/sql procedure or a pl/sql block. Excel sheet is saved on my c or d drive on my machine. In xls format.

    Depending on how big your spreadsheet is and how frequently you want to do this you might want to contruct insert statements in excel, then run these. I have done this to load a few hundred rows for a one off test on dev.
    e.g. if you have values 1 and 'a' in you spread sheet and want to insert them in to table xxx col1 & 2:
    | /|   A   |   B   |    C
    |1 |col1   |col2   |
    |2 |      1|a      |="insert into xxx ("&$A$1&","&B1&") values ("&A2&",'"&B2&"');"then paste the contents of colum C
    insert into xxx (col1,col2) values (1,'a');into sqlplus or a script.

  • HFR: How to calculate variation over last period for dynamic columns

    Hello Everyone,
                             How to calculate the period wise variation in a report where the period columns are dynamically generated from a range function? For example, the range function in the period column is &Current:Dec. What formula can I write in a calculated row so that the value is (Current  Period - Previous period)*100/Previous period ?
    Thanks,
    Sayantan

    You can add two more data rows.
    1. Use &Current
    2. Use relativemember function, select &Current, offset -1 (If you've a subvar for previous month that's the best)
    3. Add a formula row ([B]-[C]*100/[C])
    Regards
    Celvin
    http://www.orahyplabs.com

  • How to calculate average not through basic formula

    Can any bodytell me how to calculate averge of 96 rows in the quey designer  not by hard coding them.
    Is there any formula for creating it through formula or through calculations .
    And also how to calculate the maximum value and minimum value of the entire 96 rows  which is picking from a Z table -ZDC_2100.
    Iam having time blocks of 96 for 24 hrs each of  15Min.

    Hi,
    You can achieve using a counter at baselevel and use exception aggregation at query level...
    Also check the below links might be useful:
    http://help.sap.com/saphelp_nw04/helpdata/en/75/21054da1392649948e5b94e4fc4bce/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/e0173f5ff48443e10000000a114084/frameset.htm
    Hope this helps.......
    Rgs,
    I.Ravikanth

  • How to store 999999999.00000000 in sql server through ssis package?

    I have a field with 999999999.00000000 value of datatype double ?
    How to store it in ms sql server 2005 db through ssis package ?
    give me details if I have to use derived columns and what to write over there.
    please write in details as I am new to SSIS.
    Thanks in Advance.

    The value is coming from informix db .
    Can u please suggest hw to write it in my package : 
    I have taken a OLE DB Source and wrote the follwing command :
     " select CASE WHEN T1.t_maxs IS NULL THEN 0.00 ELSE T1.t_maxs END as max_inv
    from  ttiitm001010 T1 ".
    Please give details, as i am new ...

  • How to call an ODI web service through PL/SQL

    Hi All,
    Can we call an ODI web service through PL/SQL. If we can, can you please provide me info/examples/links on how to accomplish this task ?
    Any information will help me and my team.
    Am I required to use UTL_HTTP ?
    Thanks,
    Amer
    Edited by: Rooney on Nov 6, 2012 9:58 AM

    Hi,
    Take a look at this :
    http://www.business-intelligence-quotient.com/?p=1466

  • How to calculate the HFM Cube size in SQL Server-2005

    Hi
    How to calculate the HFM Cube size in SQL Server-2005 ?
    Below query used for Oracle. Then what is query for SQL Server?
    SQL> select sum(bytes/1024/1024) from dba_segments where segment_name like 'FINANCIAL_%' and owner='HFM';
    SUM(BYTES/1024/1024)
    SQL> select sum(bytes/1024/1024) from dba_segments where segment_name like 'HSV FINANCIAL%' and owner='HFM';
    SUM(BYTES/1024/1024)
    Regards
    Smilee

    What is your objective? The subcube in HFM is a concept which applies to the application tier - not so much to the database tier. The size of the subcube is the unique number of data strips (data values for January - December inclusive, for example) for the given entity, currency triplet or Parent.Child node. You have to account for parent accounts and customs which don't exist in the database but are generated in RAM in the application tier.
    So, if your objective is to find the largest subcubes, you could do this by querying the database and counting the number of records per entity/value (DCE tables) or parent.child entity combination (DCN tables). I'm not versed in SQL, but I think the script below would just tell you the schema size and not the subcube sizes.
    Check out Accelatis.com for a third party software product that can do this for you. The feature is called the Subcube Analyzer and was written by the same team that wrote HFM, so they ought to know how this works :-)
    --chris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Low battery quicker iphone 5S ios8

    Hi, I have an iphone 5S updated to ios. I have a recurrent problem : the battery can get empty in 10 hours using very few my iphone (no call, few mails, few apps). i passed 5 days in chicago, cutting of 4G and data, using only wifi last week. my batt

  • How do you add a link to a .swf file?

    Is there a way to add a link/URL to a .swf file, without embedding into the original .fla file? Is there any way to do that with just the .swf file alone, and without actually editing the .fla or re-creating it?

  • Horizontal looper in table, ASP/VBS & Access

    Hi Guys, Im using DW8 and have always just used the built in repeat region for my database results and thet repeated down the page perfectly.. Now i find myslef wanting to do something similar but I want to place images on a page and say have up to 1

  • Ftp works for start() but not for custom procedure sendFile()

    Hello, i'm busy building an ftp upload applet by using sun's ftp class sun.net.ftp.FtpClient and by including my applet in a signed jar. Now here's my problem. The code i have to ftp works fine when i put it into the applet's start() or init() proced

  • Implementation of ESS and MSS

    Hi Gurus, We are looking at implementing Employee Self Service and Manager Self Service. Please help us with the pre-requisites, kind of resources required and also the high level process. Much appreciation. Kennedy. Moved from HCM to ESS Forum Edite