Dynamic formula in DB procedure

Hello

Please help me solve the below problem.

I need to run dynamic formula in a DB that are defined in the table procedure
I have a table and formulas are defined in this one column.

PARAMETER in the table and the FORMULA as a column

FORMULA column contains dynamic formulas like
(Value2 / value1) * 100
((Value2-value1) / value1) * 100

After the extraction of this formula of table how can I replace it with values and calculate the same.

Thank you
Jen

Here is a recent discussion on the subject: {: identifier of the thread = 2497791}
You can find what you want there.

For a calculator and a generic formula parser, you might be interested in the following:

http://odieweblog.WordPress.com/2013/02/03/PLSQL-RPN-calculator/

Example:

SQL> select formula_desc
  2       , rpn_util.eval(
  3           rpn_util.parse(formula)
  4         , kv_table(
  5             kv_obj('VALUE1', 3000)
  6           , kv_obj('VALUE2', 2000)
  7           )
  8         ) as result
  9  from t_formula ;

FORMULA_DESC     RESULT
------------ ----------
EQ1          66,6666666
EQ2          -33,333333
 

Tags: Database

Similar Questions

  • DB performance decreased because of a dynamic formula

    Hi all

    I have a worried question about the dynamic formula and the performance of the db,

    My give model a solution for cash flow forecasting, so I have a member "Opening balance" in the account dimension (Dense).

    Until yesterday, this member is a stored Member but when I changed it is a dynamic (should be) the db performance declined significantly.

    I tried using "DYNCALCCACHEMAXSIZE" (set to 0) because I didn't want the dynamic cache calc will cache other resources but it was meaningless.

    When I swap back to be a member stored, good performance is back,.

    Can someone have an idea why its happened and how to improve the performance despite the dynamic formula calc?

    Thank you very much

    Yuval

    The solution is to put the account (with the opening balance member) dimension as part of the CORRECTION.

    my mistake was to find the faint of account inside the FIX for my calc bad looked like this:

    DIFFICULTY ("DENSE2",

    "SPARSE1,"

    "SPARSE2,"

    "SPARSE3")

    "Sales" = XXX;

    ENDFIX

    It seems Essbase is the calculation of all members of the account if its inside the SOLUTION and therefore it calculates the opening balance.

    I moved "Sales" to be part of the CORRECTION and put an internal sparse Member the FIX and it work like a charm.

    Thanks a lot for your answers,

    Yuval

  • A loop dynamic sql in the procedure

    Hi guys,.

    I'm having a procedure that will have two input start_date and end_date parameters

    I need a loop in alter procedure statement something like this using dynamic sql


    CHANGE TABLE M1

    SWAP PARTITION FOR (TO_DATE('01-JAN-2015','dd-MON-yyyy'))

    WITH TABLE T2

    INCLUDING THE INDEX;

    CHANGE TABLE M1

    BY EXCHANGE COMPETITION FOR (TO_DATE('02-JAN-2015','dd-MON-yyyy'))

    WITH TABLE T3

    INCLUDING THE INDEX;

    .

    .

    .


    For example I have dates in setting something like January 1, 2015-4 January 2015

    I need something like this, where T is a constant variable, I need to add T1, T2. T3 according to the dates of the range.

    Hello

    your procedure can not simply be rolled up, but the call session can be rolled up the output to a file.

    Try something like this

    col act_date noprint new_value act_date
    
    SET TERMOUT  OFF
    
    select to_char(sysdate, 'yyyy_mm_dd_hh24miss') act_date
      from dual;
    
    SET TERMOUT      ON
    set serveroutput on
    set feedback     off
    set linesize     3000
    
    col statement for a200 heading "-- alter statements"
    
    spool d:\temp\&act_date._&_CONNECT_IDENTIFIER._alter_partition.sql
    
    -- exec your_procedure
    
    -- or simple plain sql
    
    with data (start_date, end_date) as (
      select to_date('01/01/2016', 'dd/mm/yyyy'),
            to_date('05/01/2016', 'dd/mm/yyyy')
        from dual
        )
    select --level, to_char(start_date + (level - 1), 'dd-MON-yyyy' ) cur_date
                     'ALTER TABLE M1 EXCHANGE PARTITION FOR (TO_DATE(''' || to_char(start_date + (level - 1), 'dd-MON-yyyy' ) || ''',''dd-MON-yyyy'')) WITH TABLE T2 INCLUDING INDEXES;'
      || chr(10) ||  'ALTER TABLE M1 EXCHANGE PARTITION FOR (TO_DATE(''' || to_char(start_date + (level - 1), 'dd-MON-yyyy' ) || ''',''dd-MON-yyyy'')) WITH TABLE T3 INCLUDING INDEXES;'  as statement
      from data
    connect by level <= end_date - start_date + 1;
    
    spool off
    
    set feedback    on
    
    prompt @d:\temp\mk_alter.sql
    

    concerning
    Kay

  • Can be passed to the formula of the procedure/function the column value?

    Cf_value is back after some calculation using the main request.

    Can be passed directly the value of column of formulas of procedure without assinged to placeorder?
    as below...


    f_convert(:cf_value,new_value);

    ---------------------------------------------------------------

    My procedure is...


    PROCEDURE f_convert (val1 val2 in number, number) IS

    BEGIN

    val2: = val1 * 100;

    END;


    If anyone knows pls answer me...

    In fact, if there is that other calculations he (in Proceudre)

    Can I used is like below?
    ---
    PROCEDURE f_convert (val1 val2 in number, number) IS

    BEGIN

    val2: = val1 * 100;

    return (val2);
    END;
    ----

    A procedure cannot return a value, the return in my previous post clause was part of the function for formula column.
    Let's say you have a column of forms of so-called CF_2, then the function because it will be like:

    function cf_2formula return number
    is
     val1 number;
     val2 number;
    begin
    
     val2 := :cf_1 * 100; -- or val2 := val1 * 100 --parameters not allowed in formula column function
    
     -- All the other code that you need inclusive of calling function, procedure as in any PL/SQL block can be placed 
    
     return (val2);
    
    end;
    

    Any calculation can be used in the service of the formula column

  • Creating views, dynamic SQL within stored procedure

    I'm having a problem with the creation of dynamic views of in a stored procedure. The following declare block works fine:

    DECLARE
    parameter i_nom_table varchar2 (200): = 'abc ';
    xyz cursor script, SELECT step
    STARTING from scripts
    WHERE table_name = i_nom_table parameter
    ORDER BY step CAD;
    l_sql scripts.script%TYPE;
    l_step scripts.step%TYPE;
    l_error VARCHAR2 (200);
    l_code VARCHAR2 (200);
    Start
    XYZ OPEN;
    LOOP
    XYZ-FETCH INTO l_step, l_sql;
    OUTPUT WHEN xyz % NOTFOUND;
    immediately run l_sql;
    insert into ingest_log values (null, sysdate, i_nom_table, l_step, l_sql, 'Success' parameter);
    END LOOP;
    CLOSE XYZ;
    insert into ingest_log values (null, sysdate, parameter i_nom_table, 0, "Accomplished all the steps.", "Success");
    EXCEPTION WHEN OTHERS THEN
    l_error: = substr (SQLERRM, 1, 200);
    l_code: = SQLCODE;
    insert into ingest_log values (null, sysdate, parameter i_nom_table, l_step, l_sql, l_code |) ' - ERROR - ' | l_error);
    END;

    However, if I create a procedure with this block and try to run it I get an insufficient privileges error. Do not know why. All tables, views, procedures are under the same user, and the user that I'm connected as the runtime of the declare block. The user has the following privileges:

    Connect, resource, xdbadmin, s/n

    Any reason you can think of for this? Script values are generally "CREATE OR REPLACE VIEW As.... » ;

    Permissions in Oracle to do indirectly through roles are not available when compiling packages, functions, and stored procedures. Direct subsidies are required during the creation of these objects in the database.

    http://articles.TechRepublic.com.com/5100-10878_11-6183799.html

  • Calling a procedure in a dynamic pattern of antoher procedure

    Hi, as the title says, I have a procedure to call another procedure, but the schema corresponding to the second procedure in nees to be dynamic. I tried a few different ways without success.

    I tried...

    FUNCTION to CREATE or REPLACE F_Refresh_Preprocess (lv_t_name VARCHAR2, VARCHAR2 lv_t_sch)
    RETURN VARCHAR2
    AS

    BEGIN

    EXECUTE IMMEDIATE lv_t_sch | '. P_TRUNC_TAB ("' | lv_t_name |) ''')';

    END;
    /

    But I have...

    < right > diagram. P_TRUNC_TAB ('< the right name table >');
    ORA-00900: invalid SQL statement

    I confirmed that I can perform the procedure in an anonymous block.

    BEGIN
    < the right schema >... P_Trunc_Tab ('< the right name table >');
    END;
    /

    PL/SQL procedure successfully completed.


    I also tried to use DBMS_SQL. ANALYSIS/DBMS_SQL. RUN as follows...

    FUNCTION to CREATE or REPLACE F_Refresh_Preprocess (lv_t_name VARCHAR2, VARCHAR2 lv_t_sch)
    RETURN VARCHAR2
    AS

    stru_str VARCHAR2 (3000);
    CURSOR_HANDLE INTEGER.
    insert_rows VARCHAR2 (2000);

    BEGIN

    DBMS_OUTPUT. Put_line(lv_t_sch ||) '. P_TRUNC_TAB ("' | lv_t_name |) ''');');

    stru_str: = lv_t_sch | '. P_TRUNC_TAB ("' | lv_t_name |) ''');'

    CURSOR_HANDLE: = DBMS_SQL. OPEN_CURSOR;
    DBMS_SQL. PARSE (CURSOR_HANDLE, stru_str, DBMS_SQL. V7);
    insert_rows: = DBMS_SQL. EXECUTE (CURSOR_HANDLE);
    DBMS_SQL. CLOSE_CURSOR (CURSOR_HANDLE);
    COMMIT;

    END;
    /

    But I get the same error. I also tried to put the "exec" in both versions of nothing doesn't.

    Any help would be greatly appreciated.

    Dynamically, you need to run a complete PL/SQL block, i.e.

    
    EXECUTE IMMEDIATE 'BEGIN ' || lv_t_sch || '.p_trunc_tab(''' || lv_t_name || '''); END;';
    

    You probably want to use bind variables as well

    EXECUTE IMMEDIATE 'BEGIN ' || lv_t_sch || '.p_trunc_tab( :1 ); END;' USING lv_t_name;
    

    Justin

  • Dynamic insertion within the procedure error


    Hi all

    I use under oracle database on HP - UX.

    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE Production 10.2.0.5.0
    AMT for HP - UX: 10.2.0.5.0 - Production Version
    NLSRTL Version 10.2.0.5.0 - Production

    I'm not able to run the procedure below and it returns the error. The insert in the procedure returns error. If I execute manually only the insert statement, it works well.
    Can someone help me with this issue?

    Procedure
    ===========
    create or replace procedure test_proc
    as
    v_sql varchar2 (2000);
    Start
    v_sql: =' insert into TABLE1 (select owner, object_type, object_name, "S", "Y" of dba_objects@LINK1 )
    where owner = "ABC" and object_type = "TABLE" less
    Select the owner, object_type, object_name, "S", "Y" from dba_objects where owner = "ABC" and object_type = "TABLE") ';

    immediately run v_sql;
    commit;
    end;
    /

    exec test_proc;

    Error:
    ===========

    ERROR on line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "SYSTEM. TEST_PROC", line 8
    ORA-06512: at line 1

    user running this procedure doesn't have permission to read data from DBA_OBJECTS. Grant select permission on that to the user running this procedure and it should work.

    Onkar

  • Help formula: count the number of whites in a column "up to the...» »

    name string metric
    Matthew 5
    brand 1
    brand optimusPrime
    brand
    Luke 2
    Matthew jamesLikesSteak
    John 3
    Luke lukingGood
    Matthew
    Luke
    John johnnyPop
    John

    Hey guys - so I do business with a bit of a problem in number. I have a number table - the table above is a simplified representation of the corresponding parts of the table. The left column 'name' is a series of 12 names repeated and 0 missing values. The "string" middle column is a column that has a lot of missing values by a formula based on another column that is not relevant to this problem. Who is not missing is all strings. The problem I have is in the 'metric ': right column

    I am trying to create a dynamic formula which will result in the numbers and blanks, exactly as above. My goal is to create a formula that, for each line, account the number of whites in the column 'chain' until we reach an empty 'string' which occurs next to "namesake" as in the line of housing the formula - and if there is no such a situation, so that it is empty. For example, if the second row (including header row) bears the name of "Matthew". The next time that a white 'string' occurs next to the name "matthew" is tenth. The number of whites that occur between the second row, and the ninth is 5 (lines 2, 3, 5, 6 and 8). I manually coded a small part of the table to use something like this (which would be installed in cell C2 in this example):

    = IF (B2 = "", COUNTBLANK(B2:B9), "")

    This formula produces the correct number for the first row of data (5), but it does not dynamically fulfill what I'm trying to do this since I am currently having the formula to find the next blank 'chain' that occur next to "name" in the formula line.

    I hope that someone has encountered anything like this before. I tried to go through all the functions and numbers from formulas, but so far I have not found much success.

    Hi BaronDe,

    I need to ask, "why you try to do this? So what you want is possible it will be a complex solution. It may be much easier to get your information in a different way. Indicate these blanks?

    You should know that COUNTBLANK() will not count a cell with a formula, even if this formula resolves to «»

    Quinn

  • Member to the ASO cube formula

    Hi all
    I'm trying to calculate the month member when a cube of ASO.
    This formula applies; ([CDA], [and CurrMonth])-([CDA], [et PrevMonth]) but this means that the substitution variables must be defined each month. Is there a better way to make this more dynamic formula? Maybe using the CurrentMember in the formula?

    Hello

    Yes, use CDA, CurrentMember - CDA, CurrentMember.Lag (1)

    Or & CurrMonth .lag (1) for a YEAR, & CurrMonth - CDA, depending on what you want to calculate exactly.

    Used on the period dimension, Lag (1) will return the previous month.

    Thank you
    JM

    Edited by: J.M. on January 7, 2013 12:04 AM

  • Number of the formula of implementation

    I faced a problem to implement under question.

    Here is an example

    Main table

    code desc
    RECIPES 1
    2 FINANCIAL CHARGES
    3 REVENUE / Capital load., %

    Transactions table
    months of amount code process
    1 30 April 11 100
    2 5000 1 May 11

    Calculate the value of code 3 as (code 1 code 2) * 100
    I want we want to keep this formula in a table and to calculate according to the formula in the table (the formula is variable) and for this reason, we cannot write any direct formula in the procedure.
    I'm looking for help on the forum on this issue. Thanks in advance.
    create table t  as (
    select  10  REVENUES,
               100  CAPITAL_CHARGE,
              'REVENUES / CAPITAL_CHARGE' EQUATION FROM DUAL
              );
    
     -----------------------------------------------------------------
    
     SELECT
                      REVENUES, CAPITAL_CHARGE,
                       TO_NUMBER (
                          EXTRACTVALUE (
                             xmltype (
                                DBMS_XMLGEN.
                                 getxml ( 'SELECT '||EQUATION ||' RESULT FROM T'
                                   )),
                             '/ROWSET/ROW/RESULT'))
                          result
                  FROM t
    
    REVENUES     CAPITAL_CHARGE     RESULT
    10     100     0.1
    
  • dynamic stored vs

    I changed a dynamic formula as opposed to stored, and she wiped all data from this account. prospective, it works perfectly, but the retro isnce I have not run a calc (right?) is there nothing there. I insert the correct value in this account and there is not. it it automatically erases the.

    I need to be dynamic and not stored, so, how do I get there?

    You can't have two ways - dynamically calculated a member does not store data. It is fun, Essbase will not throw an error if you load a data value to a dynamic member although if you look at the output and compare the number of lines (assuming a value of data by line) with the number of changed cells, there is a difference between the two when loading the values stored in the dynamic members.

    Do you really need it for the past? Aren't core values already there?

    Kind regards

    Cameron Lackpour

  • Stupid MDX script takes more than 10 hours to run in ASO

    I inherited a stupid MDX takes more than 10 hours to run in ASO. This formula is member of the map called forecast scenario & real scenario.

    This is the equivalent of ASOsamp of it:

    I think I can shorten it to:

    (1) are the following equivalent?

    IIF (([ActualScenario],[Expense]) + 0 <>0)

    can be replaced by

    IIF (NonEmptySubset ([ActualScenario], [Expense])

    ?

    2)

    The reason I can remove almost all the lines for the PERIOD - his first line, it is already check if [period] is zero. Then, it updates level 0.

    So why would we want to write the code to update (period) levels 1, 2 and 3?  ASO is supposed to automatically consolidate all other levels 1 to 3. So why is this MDX aggregating levels 1 to 3?

    (3) in fact, I don't know why we need this Case statement:

    CASE WHEN ISLEVEL ([period]. CurrentMember, 0)

    I thought THAT MDX in Member roadmap scenario only works on members leaves (zero level).

    PS.

    The time dimension is simply

    Year

    -T1

    -Jan

    -Feb

    -Mar

    -Qtr2

    etc.

    Thank you and Merry Christmas / happy holidays!

    PS. I changed my name to "SEEP limits."

    Rolling up the quarters is the real problem. Since you have a verification statement to see if you are at level 0 do the math, you're cutting everything above level 0. Yes, it's fast - but it's because you're excluding senior level members.

    I don't know how this cube is great, but you can possibly use this formula with a procedure calc to write the data to another Member. In this way the aggregation would work without any formula.

  • restructuring of the

    Hello

    I have a question about the restructuring.

    Normally, if I add the Member in the (Dense) general plan, it takes 5 hrs. If I add the formula and a member in the dimension member dense existing properties

    It's 5 o'clock againto restructure?

    Thank you

    first result if you google "essbase restructuring":

    Essbase starts an implicit database files restructuring after a preview is changed using the contour or Dimension Build Editor. The kind of restructuring that is performed depends on the type of changes made to the sketch:

    • The dense restructuring: If a member of a dense dimension is moved, deleted, or added, Essbase restructures the blocks in the data files and creates new data files. When Essbase restructures data blocks, it automatically regenerates the index so that the index entries to point to the new data blocks. Empty blocks are not deleted. Essbase brand all the blocks that have been restructured as dirty, so after a dense restructuring, you must recalculate the database. Dense, the longest of restructuring, restructuring can take a lot of time for large databases.
    • Sparse restructuring: If a member of a sparse dimension is moved, deleted, or added, Essbase restructures the index and creates new files to index. Restructuring of the index is relatively fast; the time needed depends on the size of the index.
    • Restructuring of contour only: If a change affects only the outline of the database, Essbase does not restructure the data or index files. Change your member name, aliasing, and dynamic formula changes are examples of changes that affect only the outline of the database.
  • With the help of TWG instead of Collections of Oracle APEX

    Hello

    I use Oracle APEX v.4.2 and wanted to see if there were problems with the use of global temporary Tables (GTT) on Oracle APEX Collections. I remember reading another post here that mentioned that there are problems with the session ID and TWG.

    Basically, I want to call a procedure of package from dynamic action where this procedure will perform a form any treatment and insert records into a TWG, which I would then use to dial from a classic APEX SQL report. I seeks to implement the TWG to preserve the lines and run an EXECUTE IMMEDIATE 'TRUNCATE TABLE TWG' within the APEX statement.

    Can someone pls let me know of any problems with the above scenario or I better stick to the Collections of the APEX.

    Hope to hear from someone soon on the above and, possibly, examples of use of TWG in a similar way.

    Thank you.

    Tony.

    You cannot use with APEX, since TWG is bound to a specific database session (aka connection)-> see DECLARE GLOBAL TEMPORARY TABLE statement

    As with APEX you can (and will) get a different Session DB for each load/submit/ajax-call of a page, you will never see the TWG previously created again.

    Peter

  • Please help me with the Alternative of queries to replace the UNION ALL for two queries

    Hi all

    I have the query to retrieve assets employees salary count and in so far as below:

    Select ename, emp_no, sum (sal_till_2010), sum (sal_till_2014) of

    (select emp_no, ename, salary as sal_till_2010, 0 as sal_till_2014 of employee e1

    where effective_date < = 1 January 2010 ' and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = January 1, 2010 "")

    UNION ALL

    Select ename, emp_no, 0 as sal_till_2010, salary as employee e1 sal_till_2014 - here is a dummy 0 salary until 2010 for the union of all the

    where effective_date < = 1 January 2014 "and not exists (select 1 from e2 employee_deletion where e2.emp_no = e1.emp_no and e2.deletion_date < = 1 January 2014") "

    Group of emp_no, ename;

    In this query, I get the total salary until 2010 and until 2014 in the employee table, dates are dynamically passed to the procedure, and this can change.

    But assume the date above and let me know the alternative of queries to improve performance because I use Union ALL and read the same table twice in the above query.

    Advice me with request to read the table once to fetch the same data as the above query.

    Thanks in advance.


    Hello

    Thanks for the display of the data of the sample; It's very useful!

    I think OP wants something like this:

    WITH cutoff_dates AS

    (

    SELECT TO_DATE (January 1, 2010 ', ' DD/MM/YYYY') AS cutoff_date, 2010 UNDER the label OF dual UNION ALL

    SELECT TO_DATE (1 January 2014 ', "DD/MM/YYYY"), double 2014

    )

    SELECT e.emp_no, e.ename

    , NVL (SUM (CASE WHEN c.label = 2010 THEN e.salary END), 0) AS sal_till_2010

    , NVL (SUM (CASE WHEN c.label = 2014 THEN e.salary END), 0) AS sal_till_2014

    E employee

    JOIN cutoff_dates c ON e.effective_date<=>

    WHERE DOES NOT EXIST)

    SELECT 1

    Of employee_deletion ed

    WHERE ed.emp_no = e.emp_no

    AND ed.deletion_date<=>

    )

    E.emp_no GROUP, e.ename

    ORDER BY e.emp_no

    ;

    Output of your sample data:

    EMP_NO ENAME SAL_TILL_2010 SAL_TILL_2014

    ---------- ------ ------------- -------------

    1 Mickey 450 0

    2 Donald 750 0

Maybe you are looking for