Calling a procedure dynamically

Suppose that a_function_name returns an integer.
I want to do something like :
EXECUTE IMMEDIATE 'package_name.proc_name(a_function_name)';
I need this to remove code duplication dramatically.
EXECUTE IMMEDIATE says that this is not valid SQL. If EXECUTE IMMEDIATE cannot execute PL/SQL than do I need something else? I have a procedure name at runtime and want to call it. Is it possible?
Thank you.

> But PL/SQL is not the right place to do this I think.
PL/SQL can do everything you can do in Java. My entire application tier is PL/SQL and resides in Oracle.
My systems do not use Java at all - except for the odd Java stored proc. The J2EE guys we have, have now too begun to code 90% of their applications in PL/SQL, only using Java to do the rendering. They use JBoss for rendering. I use APEX.
> Complex logic in stored procedures caused that. And that procedures are
not formed in an object oriented fashion which makes them hard to test.
That is the choice you as developer make - how to use PL/SQL. It does support o-o.
And alluding that procedural code is more difficult to test than o-o code.. I differ on that. In fact, o-o has a lot more hidden complexities that one does not have with procedural code.
> I see that, object oriented approaches encourage object to relational
mapping and no business logic stored in the database. Than all you need is
CRUD SQL and all you need to test is CRUD.
Utter bs. That is the single primary reason for the failure of so many systems. The database is not a bit bucket. And J2EE is a failure because of this bit bucket approach.
If you only need a persistence layer for app code, then a RDBMS is not needed. Especially not Oracle.
But you do need a database. Why? Because the app server is incapable of being a database as good as what the database tier is.
What I really do not understand is that people who are o-o schooled, should be the very first to realise the benefits of importance of the data, the importance of encapsulating code with data - and yet, design the application in one tier and wants the data in another tier.
Fact is that PL/SQL is even more capable than Java or .Net in this regard. Fact is that Oracle is not just a bit bucket, but the most advance RDBMS product on this planet and very capable of encapsulating the COMPLETE app tier.
Fact is, it does this cheaper and faster and more scalable than an app server.
And ignoring these facts is why the majority of J2EE systems are failures at the end of the day.

Similar Messages

  • Calling a procedure dynamically in forms

    Hi all
    I'm using Oracle 6, is there anyway to call a procedure dynamically, i mean the procedure called differs according to a certain condition. The procedure is local in the form not in the database, how can this be achieved
    Thanks

    Hello,
    user497979 wrote:
    what i want is as the following
    IF cond = 1 THEN
    proc1;
    ELSIF cond = 2 THEN
    proc2;
    ELSIF cond = 3 THEN
    proc3;
    .................. so onWell, i think the way you are showing with IF CONDITION is smart enough to call the procedures. And it will be also easy to understand.
    I'm searching for a way to call the procedure as follows
    proc||cond for exampleBut why? What is the purpose to do like this? Any efficiency or any logical reason?
    Another option You can create one procedure and call the code depend on parameter you pass like
    PROCEDURE MY_PROC(pCond IN NUMBER) IS
    BEGIN
      IF pCond=1 THEN
        -- Do something here...
      ELSIF pCond=2 THEN
       -- Do something here...
      ELSE
       -- Do something here...
      END IF;
    END;And while calling the procedure you can call the procedure by passing the value of pCond upon your requirement like
    MY_PROC(<parameter value>);But still the IF CONDITION exists either you use inside or outside the procedure.
    -Ammad

  • Call stored procedure dynamically?

    I wrote a bunch of programs in Perl to output different reports. All these programs are very similar: calling a stored procedure in SQL Server, dump the ResultSet into the file in disk ...
    My boss asked me to write a "Generic" program to combine these programs together so that we don't need write endless similar programs any more.
    I decide to write this program in Java. The new program is supposed to take a stored procedure call as an input parameter (reading from a configuration file, maybe?). It will be great if the program can dynamically determine the field names in the ResultSet from the stored procedure call. In another word, there shouldn't be any hard coded field names in the Java Code. The more generic of the program, the better.
    Is this doable? Does anyone have any such experience before? Any idea or recommendation is highly appreciated.
    Thanks a lot,
    - LX

    Here is some that I wrote:
    //Here is a snippet out of my main program:
                   md = rs.getMetaData();
                   noOfColumns = md.getColumnCount();     
                   //Generate the sql for our prepared statement insert
                   sql = buildInsertSQL("DWXP111", noOfColumns);
                   lowLevel.info("SQL:" + sql);
                   //Create the prepared statment
                   ps = legacyCon.prepareStatement(sql);
                   //Set the prepared statement input parameters
                   while(rs.next())
                        for(int x=1; x<noOfColumns+1; x++)
                             setParameters(x, md.getColumnType(x));     
                        //Execute the prepared statement
                        checkForSuccess(ps.executeUpdate());                    
    //Here is the method it calls:
         private void setParameters(int columnNo, int dataType)
              lowLevel.info("Setting parameter number: " + columnNo);
              lowLevel.info("Data type:" + dataType);
              try
                   switch(dataType)
                        case Types.VARCHAR:
                             ps.setString(columnNo, rs.getString(columnNo)==null ? "" : rs.getString(columnNo).toUpperCase());
                             lowLevel.info("String set:" + rs.getString(columnNo));
                             break;
                        case Types.DECIMAL:
                             ps.setString(columnNo,  rs.getBigDecimal(columnNo)==null ? "0" : rs.getBigDecimal(columnNo).toString());
                             lowLevel.info("Decimal set");
                             break;
                        case Types.CHAR:
                             ps.setString(columnNo,  rs.getBigDecimal(columnNo)==null ? "0" : rs.getBigDecimal(columnNo).toString());
                             lowLevel.info("Char set");
                             break;
              catch (SQLException e)
                   lowLevel.warn("Error while setting parameters for " + dataType + " info");
                   e.printStackTrace();
         }

  • Calling Stored procedures dynamically

    Hi ,
    I'm trying to call different Stored prcedures from my Java program based on different conditions.
    I have the column values need to be passed as input params to the Stored Procedures.
    But the sequence of values and the sequence of the input params inthe stored proc is different and morover the no of input params is different for different stored procedures.
    Does anybody have any knowledge how to call dynamically the stored procedures or generalise the calls to some extent.
    Any idea or thought will be appreciated.
    Thanks
    Krish

    Hi ,
    I'm trying to call different Stored prcedures from my
    Java program based on different conditions.
    I have the column values need to be passed as input
    params to the Stored Procedures.
    But the sequence of values and the sequence of the
    input params inthe stored proc is different and
    morover the no of input params is different for
    different stored procedures.
    Does anybody have any knowledge how to call
    dynamically the stored procedures or generalise the
    calls to some extent.
    Any idea or thought will be appreciated.You need a simple interpreter/mapper.
    Basically your problem is broken in to the following.
    1. (set of params) maps to (proc)(param handler)
    2. Analyze params to get map value.
    3. Use param handle to populate proc
    4. Call proc
    5. Return values.
    The last step is more complicated if you need to return a specialized version of the values. But in that case just add a (populate values handler) to the map.
    Note that if you are doing this because you don't want to write code versus a real business need then you should investigate code generation. Generated code is easier to understand, easier to maintain and it faster versus using a generic handler.

  • Calling stored procedure dynamically

    Hello,
    I have a feeling this is not possible but was wondering if it is possible to have a call within a package to a stored procedure that is outside the said package? And can a stored procedure outside a package call another stored procedure that is also outside a package?
    Reason is, i have a couple of packages that both contain a procedure that is exactly the same so for efficiency can i have the stored procedure that is used by both packages stored outside the packages where it can be called by them both?
    Thanks in advance

    Ah!!! So if i had for example, a stored procedure called total_Customers in Package1 and required to use this >in Package2, i could then have a call within Package2 that said;
    Package1.total_CustomersYes, if the procedure total_Customers in Package1 has been declared in the package specification
    I recommend you to study the PL/SQL User's Guide and Reference
    What Is a PL/SQL Package?
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/09_packs.htm#362
    Message was edited by:
    Jens Petersen

  • Calling SQL stored procedure dynamically

    Hallo,
    could anybody tell me how to call HANA SQL stored procedure dynamically?
    The coding looks like this:
    v_ProcedureName := '"' || KpiNamespace || '::' || KpiName || '"';
    v_SQL := 'CALL ' || :v_ProcedureName || '( lt_outKPI )';
    EXEC :v_SQL;
    For this call I get the error message:
    "Transaction rolled back by an internal error: wrong number or types of parameters in call: Physical table is not allowed in OUT table variable position: LT_OUTKPI: line 1 col 55 (at pos 54)"
    The procedure to be called dynamically has a table output parameter.
    Thanks in advance,
    Best Regards,
    Alexey Romanov.
    Hi Alex,
    Can you share your requirement on exactly what is the need to call the procedure dynamically?
    For your question, have a look on the below:
    1) Have a procedure named EMPLOYEE_DETAILS
    http://scn.sap.com/servlet/JiveServlet/downloadImage/2-14895702-415799/236-170/pastedImage_0.png
    2) Created one more procedure named Dynamically as shown below:
    CREATE PROCEDURE Dynamically ()
    AS
    BEGIN
    DECLARE QUERY VARCHAR(1000);
    QUERY := 'call  EMPLOYEE_DETIALS(?)';
    EXECUTE IMMEDIATE (:QUERY);
    END;
    3) Output:
    http://scn.sap.com/servlet/JiveServlet/downloadImage/2-14895702-415800/210-189/pastedImage_3.png
    Regards,
    Krishna Tangudu
    Hi Krishna,
    Thanks for your reply!
    Unfortunately, I can neither go to ‘full discussion’, nor open the pictures, you have attached, nor see you reply.
    That’s why I just add my reply to the problem description.
    The procedure name is composed out of 2 parts on-the-fly, that is why I have to call it dynamically:
    create local temporary table "#KPIEvals"(           
              "KpiNamespace" NVARCHAR(256) CS_STRING,           
              "KpiName" NVARCHAR(32) CS_STRING,               
              "KpiText" NVARCHAR(256) CS_STRING,           
              "Responsible" NVARCHAR(256) CS_STRING );
    FOR cur_row as c_cursor DO        
         v_SQL := '';     
         v_ProcedureName :=  '"' || cur_row."KpiNamespace" || '::' || cur_row."KpiName" || '"';     
         v_SQL := 'CALL ' || :v_ProcedureName || '( lt_outKPI )';     
         EXEC :v_SQL;                
         v_SQL := 'INSERT INTO "#KPIEvals" SELECT * FROM :lt_out_kpi';     
         EXEC :v_SQL;                
    END FOR;
    I guess there might be 2 reasons for the problem:
    1.     All the procedures are called dynamically in a loop.
    2.     All the procedures have an output parameter, which is a table.
    Hope that helps,
    Best Regards,
    Alex.

    Hi Alexey, I think what you may need to do in this case is to do the insert into your temp table from within the dynamically called procedure, therefore no need for output param in your procedure call. You can then select from the temp table in your main procedure. Hope that makes sense.
    Peter

  • Calling a procedure from Dynamic Page

    I am trying to call a procedure from a dynamic page. The procedure displays multi records from a table. I have created a procedure:
    PROCEDURE process_student_request( p_primary_request in wwv_utl_api_types.vc_arr,
    p_alternate_request in wwv_utl_api_types.vc_arr,
    p_action in varchar2,
    l_status in out varchar2);
    When I hit the submit button on the dynamic page it does not execute the procedure and tries to open a new page. How do I get this to work?
    Here is the text of the page:
    <HTML>
    <HEAD>
    <TITLE>Example</TITLE>
    </HEAD>
    <BODY>
    <FORM action="portal30.star_portal.process_student_requests" method="post">
    <TABLE BORDER="0" WIDTH="100%" CELLPADDING="2" CELLSPACING="0" class="RegionBorder">
    <TR>
    <TD valign="top" align="left" width="40%"><FONT class="PortletText1">
    <ORACLE>declare
    row_num number := 1;
    hold_row_num number;
    hold_class_cd stars3.req.class_cd%TYPE;
    begin
    for c1 in (select A.start_yy, A.school, A.student_id, A.class_cd, B.name from stars3.course B, stars3.req A
    where A.student_id = portal30.star_portal.get_session_variable('STUDENT_ID') and A.start_yy = '01' and
    A.alternate_no = '0' and
    B.start_yy = A.start_yy and
    B.school = A.school and
    B.class_cd = A.class_cd)
    loop
    hold_class_cd := c1.class_cd;
    htp.p(lpad(to_char(row_num),2,'0'));
    htp.p('<select name="p_primary_request">');
    htp.p('<option value="' || c1.class_cd|| '">' || c1.name || '</option>');
    row_num := row_num + 1;
    htp.p('<BR>');
    end loop;
    htp.p('<input type="submit" name="p_action">');
    end;
    </ORACLE>
    </BODY>
    </FORM>
    </TD>
    </TR>
    </TABLE>
    </HTML>

    Bob,
    You have variables in your procedure like l_status, p_alternate_status which you do not have in the form. Are these IN or OUT variables ?
    If these are IN variables, this proc will not work because you do not have any variable in the form. So from where does it get the values? There is not any default declared too. You have to explicitly define IN or OUT variables.
    Have you also given execute permission to public ?

  • Dynamic Page that calls DB procedure to update data gets PLS222 or PLS306

    This seems a bit odd to me: I'm getting either "procedure no in scope" (when I call a procedure with the right args) or "wrong # or type of arguments" (when I call it with the wrong ones, so it is checking the procedure) in a dynamic page.<P>
    I'm trying to build a dynamic page that will display data and checkboxes (basically to get around the multi-select limitations -- management has told me that the "fake" md form is not acceptable)<P>
    So I build the page, it displays the data just fine exactly as we want it to:<P>
    <HTML><FORM><ORACLE>declare
    p_mdoc_user portal.wwv_utl_api_types.vc_arr;
    p_mdoc_user_seq portal.wwv_utl_api_types.vc_arr;
    p_seg_id portal.wwv_utl_api_types.vc_arr;
    p_cb portal.wwv_utl_api_types.vc_arr;
    p_action varchar2(20):='Save Changes';
    begin
    htp.p('Select your segments');
    htp.p('< p>');
    htp.p('<table border=2 cellpadding=2 cellspacing=0>');
    htp.tablerowopen;
    htp.tableheader('Seg#');
    htp.tableheader('Included');
    htp.tablerowclose;
    for r1 in (select seg_id, build_seg
    from web.mdoc_create_seg
    where mdoc_user = :mdoc_user
    and mdoc_user_seq = :mdoc_user_seq)
    loop
    htp.p('<input_type="hidden" name="p_mdoc_user" value='||:mdoc_user||'>');
    htp.p('<input_type="hidden" name="p_mdoc_user_seq" value='||:mdoc_user_seq||'>');
    htp.p('<input_type="hidden" name="p_seg_id" value='||to_char(r1.seg_id)||'>');
    htp.p('<tr><td>');
    htp.p(r1.seg_id);
    htp.p('</td><td>');
    if r1.build_seg='TRUE' then
    htp.p('<input type="checkbox" name="p_cb" value="Y" checked>');
    else
    htp.p('<input type="checkbox" name="p_cb" value="Y">');
    end if;
    htp.p('</td></tr>');
    end loop;
    htp.p('</table>');
    htp.p('< p>');
    /*note, this is where I'm putting in a procedure call to update*/
    end;
    </ORACLE></FORM></HTML><P>
    so then I try to add the procedure call (where the sql*plus comment is above)<P>
    htp.p('<input type="button" value="Save Changes" onclick='||
    mdoc_seg_create_choice_p(
    p_mdoc_user,
    p_mdoc_user_seq,
    p_seg_id,
    p_cb)
    ||'>');<P>
    When I try to run as portlet, I get pls 222 not in scope. <but>
    When I take a value out (say remove the last ",p_cb") - I get pls 306 wrong number or type of args to call.<P>
    I've granted the procedure and its underlying tables to portal/public/and portal_public, even though I'm building the dynamic page under a DB provider that is the same as the schema I wrote the procedure in.<P>
    I've tried specifying the schema, using a public synonym, and putting it in a package: same thing occurs, either I get pls 00222 not in scope when I call it with the right columns, or if I purposefully leave one out I get PLS 00306 wrong # or type of args.<P>
    Any ideas?
    -Mike

    Hi guys
    Check out the last 2 posts in this thread for ideas on how to implement 1.
    Report on user data from LDAP
    Varad

  • Calling procedure dynamically, from different schema, permissions issue

    Hi,
    I have a 'master_user' schema that needs to run DDL on a 'secondary_user' schema.
    There appears to be some kind of permissions subtlety that I'm missing. Here are the simplified steps to create, test and troubleshoot:
    Secondary schema has a procedure defined:
    -- Run as SYSTEM (at build time)
    CREATE OR REPLACE PROCEDURE secondary_user.execute_immediate(p_sql_statement IN VARCHAR2)
    IS
    BEGIN
        EXECUTE IMMEDIATE p_sql_statement;
    END;
    GRANT EXECUTE ON secondary_user.execute_immediate TO master_user;
    I then want to call this procedure from master_user to execute DDL dynamically in secondary_user.
    - Run as master_user
    BEGIN
        EXECUTE IMMEDIATE ' BEGIN secondary_user.execute_immediate(''DROP TABLE test1''); END;';
    END;
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at SECONDARY_USER.EXECUTE_IMMEDIATE", line 5
    ORA-06512: at line 1
    ORA-06512: at line 2
    TROUBLESHOOTING SO FAR:
    Now I can call this procedure directly:
    -- As master_user
    EXEC secondary_user.execute_immediate('drop table test1')
    PL/SQL procedure successfully completed.
    I can call the wrapped procedure as different users:
    -- As secondary_user
    BEGIN
        EXECUTE IMMEDIATE ' BEGIN secondary_user.execute_immediate(''DROP TABLE test1''); END;';
    END;
    PL/SQL procedure successfully completed.
    -- As SYSTEM
    BEGIN
        EXECUTE IMMEDIATE ' BEGIN secondary_user.execute_immediate(''DROP TABLE test1''); END;';
    END;
    PL/SQL procedure successfully completed.
    Can you shed any light on this behaviour? The master_user clearly has permission to run the procedure, but it cannot see it from within an anonymous block. However SYSTEM can so what permission does SYSTEM have that master_user does not?
    Much appreciated,
    Si

    Something doesn't add up:
    SCOTT@orcl > create user secondary_user
      2  identified by secondary_user
      3  default tablespace users
      4  quota unlimited on users
      5  /
    User created.
    SCOTT@orcl > grant create session to secondary_user
      2  /
    Grant succeeded.
    SCOTT@orcl > create user master_user
      2  identified by master_user
      3  default tablespace users
      4  quota unlimited on users
      5  /
    User created.
    SCOTT@orcl > grant create session to master_user
      2  /
    Grant succeeded.
    SCOTT@orcl > CREATE OR REPLACE PROCEDURE secondary_user.execute_immediate(p_sql_statement IN VARCHAR2)
      2
      3  IS
      4
      5  BEGIN
      6
      7      EXECUTE IMMEDIATE p_sql_statement;
      8
      9  END;
    10
    11  /
    Procedure created.
    SCOTT@orcl > GRANT EXECUTE ON secondary_user.execute_immediate TO master_user;
    Grant succeeded.
    SCOTT@orcl >
    SCOTT@orcl > create table secondary_user.test1(n number)
      2  /
    Table created.
    SCOTT@orcl > connect master_user@orcl
    Enter password:
    Connected.
    MASTER_USER@orcl > BEGIN
      2
      3      EXECUTE IMMEDIATE ' BEGIN secondary_user.execute_immediate(''DROP TABLE test1''); END;';
      4
      5  END;
      6
      7  /
    PL/SQL procedure successfully completed.
    MASTER_USER@orcl >
    Make sure table secondary_user.test1 exists when you run SP. And, as you can see, neither secondary_user nor master_user have any privs besides create session.
    SY.

  • Getting ora-00900 error when calling the procedure with the dynamic sql.

    create or replace procedure dyn_update(tab in varchar2,col in VARCHAR2) as
    BEGIN
    execute IMMEDIATE 'update'||tab||'set'||col||'= 0 where order_id=2458';
    end;
    and when i call this procedure in sql developer or sql* plus using
    begin
    dyn_update('Orders',Order_status');
    end;
    I am getting the oracle 0ra 00900 error.
    can any one please help me

    just a tip:
    Create your dynamic string in a local variable, so you can easily see why it is giving an exception
    create or replace procedure dyn_update(tab in varchar2,col in VARCHAR2) as
       str varchar2(32767);
    BEGIN
       str := 'update '||tab||' set'||col||'= 0 where order_id=2458';
       dbms_output.put_line (str);
      execute IMMEDIATE str;
    end;

  • Creating parameters dynamically and calling a procedure but strange issue

    Okay I have the following program that is calling a procedure(data_compare_utility)[pasted below] and data_compare_table_setup table definition and data(isert scripts) are pasted below :
    DECLARE
    --FP_OLD_TABLE VARCHAR2(200);
    --FP_NEW_TABLE VARCHAR2(200);
    --FP_DATA_COMPARE_ID NUMBER(10) := 1;
    --FP_RESTRICTION_CLAUSE VARCHAR2(500) := 'WHERE W_INSERT_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'') OR W_UPDATE_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'')';
    --FP_RESTRICTION_CLAUSE_4_INS VARCHAR2(500) := 'WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')';
    cursor c_data_compare_table_setup
    is
    select table_name, old_schema_name, new_schema_name, data_compare_id, restriction_clause, restriction_clause_ins from DATA_COMPARE_TABLE_SETUP;
    r_of_data_compare_table_setup c_data_compare_table_setup%rowtype;
    Lv_args_4_data_compare_utility varchar2(500);
    BEGIN
    --FP_OLD_TABLE := 'BIAPPS_11.RAHUL_EMPLOYEES';
    --FP_NEW_TABLE := 'RAHULKALRA.RAHUL_EMPLOYEES';
    open c_data_compare_table_setup;
    Loop
    fetch c_data_compare_table_setup into r_of_data_compare_table_setup;
    exit when c_data_compare_table_setup%NOTFOUND;
    --exec RAHULKALRA.P_COMPARE_DATA_UTILITY
    Lv_args_4_data_compare_utility := ''''||r_of_data_compare_table_setup.OLD_SCHEMA_NAME||'.'||r_of_data_compare_table_setup.TABLE_NAME||''','''||r_of_data_compare_table_setup.NEW_SCHEMA_NAME||'.'||r_of_data_compare_table_setup.TABLE_NAME||''','||r_of_data_compare_table_setup.DATA_COMPARE_ID||','''||r_of_data_compare_table_setup.RESTRICTION_CLAUSE||''','''||r_of_data_compare_table_setup.RESTRICTION_CLAUSE_INS||'''';
    P_COMPARE_DATA_UTILITY(Lv_args_4_data_compare_utility);
    commit;
    End Loop;
    dbms_output.put_line('rahul');
    dbms_output.put_line(''''||r_of_data_compare_table_setup.OLD_SCHEMA_NAME||'.'||r_of_data_compare_table_setup.TABLE_NAME||''','''||r_of_data_compare_table_setup.NEW_SCHEMA_NAME||'.'||r_of_data_compare_table_setup.TABLE_NAME||''','||r_of_data_compare_table_setup.DATA_COMPARE_ID||','''||r_of_data_compare_table_setup.RESTRICTION_CLAUSE||''','''||r_of_data_compare_table_setup.RESTRICTION_CLAUSE_INS||'''');
    --P_COMPARE_DATA_UTILITY('BIAPPS_11.RAHUL_EMPLOYEES','RAHULKALRA.RAHUL_EMPLOYEES',1,'WHERE W_INSERT_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'') OR W_UPDATE_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'')','WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')');
    --P_COMPARE_DATA_UTILITY('BIAPPS_11.RAHUL_EMPLOYEES','RAHULKALRA.RAHUL_EMPLOYEES',1,'WHERE W_INSERT_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'') OR W_UPDATE_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'')','WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')');
    close c_data_compare_table_setup;
    END;
    Procedure : compare_data_utility:
    CREATE OR REPLACE procedure RAHULKALRA.p_compare_data_utility(fp1_old_table in varchar2, fp2_new_table in varchar2, fp3_data_compare_id in number, fp4_restriction_clause in varchar2, fp5_recrtiction_clause_4_ins in varchar2)
    as
    Lv_common_column_names varchar2(2000);
    Lv_primary_column_name varchar2(50);
    Lv_insert_data_compare_log varchar2(2000);
    --Lv_counter number(10);
    Lv_row_id_for_data_compare_log number(10);
    Lv_old_table_record_count number(10);
    Lv_old_table_rec_cnt_query varchar2(200);
    Lv_new_table_record_count number(10);
    Lv_new_table_rec_cnt_query varchar2(200);
    begin
    select max(row_id) into Lv_row_id_for_data_compare_log from data_compare_log;
    Lv_old_table_rec_cnt_query := 'Select count(*) from '||fp1_old_table||' '||fp4_restriction_clause;
    dbms_output.put_line(Lv_old_table_rec_cnt_query);
    execute immediate Lv_old_table_rec_cnt_query into Lv_old_table_record_count;
    Lv_new_table_rec_cnt_query := 'Select count(*) from '||fp2_new_table||' '||fp4_restriction_clause;
    execute immediate Lv_new_table_rec_cnt_query into Lv_new_table_record_count;
    dbms_output.put_line(fp5_recrtiction_clause_4_ins);
    if (Lv_row_id_for_data_compare_log is null)
    then
    Lv_row_id_for_data_compare_log := 1;
    else
    Lv_row_id_for_data_compare_log := Lv_row_id_for_data_compare_log + 1;
    end if;
    Lv_insert_data_compare_log := 'insert into data_compare_log values('||Lv_row_id_for_data_compare_log||',''comparing data for '||fp1_old_table||' and '||fp2_new_table||''','''||fp1_old_table||''','''||fp2_new_table||''',TO_DATE('''||to_char(sysdate,'DD-MON-YY HH24:MI:SS')||''',''DD-MON-YY HH24:MI:SS''),'||fp3_data_compare_id||','||Lv_old_table_record_count||','''||'Select count(*) from '||fp1_old_table||' '||fp5_recrtiction_clause_4_ins||''','||Lv_new_table_record_count||','''||'Select count(*) from '||fp2_new_table||' '||fp5_recrtiction_clause_4_ins||''')';
    dbms_output.put_line(Lv_insert_data_compare_log);
    execute immediate Lv_insert_data_compare_log;
    commit;
    -- tested : dbms_output.put_line(Lv_insert_data_compare_log);
    Lv_common_column_names := f_fetch_common_column_names(fp1_old_table,fp2_new_table,fp3_data_compare_id);
    -- tested : dbms_output.put_line(Lv_common_column_names);
    Lv_primary_column_name := f_extract_pkey_column_names(fp1_old_table, fp2_new_table);
    dbms_output.put_line(Lv_primary_column_name);
    p_compare_data(fp1_old_table,fp2_new_table,Lv_common_column_names,Lv_primary_column_name,fp4_restriction_clause,fp3_data_compare_id);
    end;
    CREATE TABLE RAHULKALRA.DATA_COMPARE_TABLE_SETUP
    TABLE_ID NUMBER(10),
    TABLE_NAME VARCHAR2(100 BYTE),
    OLD_SCHEMA_NAME VARCHAR2(100 BYTE),
    NEW_SCHEMA_NAME VARCHAR2(100 BYTE),
    RESTRICTION_CLAUSE VARCHAR2(500 BYTE),
    RESTRICTION_CLAUSE_INS VARCHAR2(500 BYTE),
    DATA_COMPARE_ID NUMBER(10)
    Insert into DATA_COMPARE_TABLE_SETUP
    (TABLE_NAME, OLD_SCHEMA_NAME, NEW_SCHEMA_NAME, DATA_COMPARE_ID, RESTRICTION_CLAUSE, RESTRICTION_CLAUSE_INS)
    Values
    ('W_CHNL_TYPE_D', 'BIAPPS_11', 'RAHULKALRA', 1, 'WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')', 'WHERE W_INSERT_DT >= TO_DATE(''''''''01/JAN/2012'''''''',''''''''DD/MON/YYYY'''''''') OR W_UPDATE_DT >= TO_DATE(''''''''01/JAN/2012'''''''',''''''''DD/MON/YYYY'''''''')');
    Insert into DATA_COMPARE_TABLE_SETUP
    (TABLE_NAME, OLD_SCHEMA_NAME, NEW_SCHEMA_NAME, DATA_COMPARE_ID, RESTRICTION_CLAUSE, RESTRICTION_CLAUSE_INS)
    Values
    ('RAHUL_EMPLOYEES', 'BIAPPS_11', 'RAHULKALRA', 1, 'WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')', 'WHERE W_INSERT_DT >= TO_DATE(''''''''01/JAN/2012'''''''',''''''''DD/MON/YYYY'''''''') OR W_UPDATE_DT >= TO_DATE(''''''''01/JAN/2012'''''''',''''''''DD/MON/YYYY'''''''')');
    I am facing the following error for this command when I call P_compre_data_utility procedure from my anonymous block:
    P_COMPARE_DATA_UTILITY(Lv_args_4_data_compare_utility); -- the error is pasted below
    if I do a dbms_output.put_line(Lv_args_4_data_compare_utility) and then copy paste its output and call P_COMPARE_DATA_UTILITY, the procedure is getting executed, here is that command :
    P_COMPARE_DATA_UTILITY('BIAPPS_11.RAHUL_EMPLOYEES','RAHULKALRA.RAHUL_EMPLOYEES',1,'WHERE W_INSERT_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'') OR W_UPDATE_DT >= TO_DATE(''01/JAN/2012'',''DD/MON/YYYY'')','WHERE W_INSERT_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''') OR W_UPDATE_DT >= TO_DATE(''''01/JAN/2012'''',''''DD/MON/YYYY'''')');
    Error:
    ORA-06550: line 27, column 7:
    PLS-00306: wrong number or types of arguments in call to 'P_COMPARE_DATA_UTILITY'
    ORA-06550: line 27, column 7:
    PL/SQL: Statement ignored
    Question : just want to know whats wrong with : P_COMPARE_DATA_UTILITY(Lv_args_4_data_compare_utility);
    please help me.
    Regards
    Rahul

    Mac_Freak_Rahul wrote:
    Hi All,
    I am really sorry, my head is so aching since I am not a regular plsql coder and to save my life I need to write this code for data comparison between 2 tables .. further sorry about calling p_data_compare utility stupidly : P_COMPARE_DATA_UTILITY(Lv_args_4_data_compare_utility);
    I am calling it now using :
    execute immediate 'exec P_COMPARE_DATA_UTILITY('||Lv_args_4_data_compare_utility||')';If you are sure the call works then, exec would not work since it is a SQLPLUS command.
    try
    execute immediate 'BEGIN P_COMPARE_DATA_UTILITY(''||Lv_args_4_data_compare_utility||''); END;';
    PS: I can manually give table names to my utility , just need 60 tables to compare but would be great if I can work it out this eay.
    2) I can sound very stupid since my head is aching I am not a regular plsql coder but from now on I would be one, please helpJust for your sake, to Compare 60 tables (Supposing you just want to verify count of records), you are writing an entire procedure; You might have completed this activity by now doing the manual way. By taking this way, you are investing time to generate a correct code (as you just mentioned not being a regular plsql developer) you are stuck with some un-identifiable issues.
    As an alternate way, I would suggest you to export the data, after ordering, into a spreadsheet and then validate. Also, since it looks like you are comparing the data in the same database between schemas, you can also use the SQL Navigators Data Compare utility and there are many more readily available in market.
    I would wish you the best if you still prefer taking the approach.

  • Dynamically call another procedure

    In SQLServer you can have a variable that holds a procedure
    name. The variable can then be used in the execute statement.
    Is there any way in PLSQL to dynamicaly call another procedure.
    example:
    begin
    declare procname varchar2(32) = 'proc1';
    --now call the procedure
    procname -- ?
    execute immediate procname -- ?
    end;
    Thanks,
    Dermot.

    Just wrap it in an anonymous block:
    create or replace procwrap
    (p_procname in varchar2)
    is
    begin
    execute immediate 'begin ' || p_procname || '; end;';
    end;

  • Two related questions: using htmldb_Get to call stored procedure and passing in an array of items

    I have the need to save dynamically generated ApEx items via AJAX.  I am using APEX_ITEM API to generate the items.  At run-time, I have no idea how many of items will be generated on the page, but I know that they will all have discreet and distinct "name" attributes, i.e. f01, f02, f03, etc.  As a basic example, if I have to generate a select list, I know that the "p_idx" parameter of the APEX_ITEM call is say "3", so all select lists that get generated will have a "name" attribute in the DOM of "f03", all text items will be "f01", etc.
    I want to save this data to the database via AJAX.  It is typical to call the standard htmldb_Get javascript function for use of an on-demand process, but I am interested in using the rarely-called-upon "procedure" and queryString" options of that javascript function so that I can build the queryString on the fly based on what is on the DOM when the tries to save the data they entered into these APEX_ITEM-generated items.  Does anyone have any good examples of how to use the "procedure" and "queryString" parameters of the htmldb_Get javascript function?
    I have found a smattering of some blogs, posts, etc. online related to this, but mostly just people regurgitating the documentation.  I found this post (https://forums.oracle.com/thread/2549237) which had a glimpse of hope to be able to pass an array (which is something I will need) as a parameter, but would like someone to sanity check this before I go down that road.
    Shane.
    ApEx 4.2.1

    Shane
    Since you mention you are on APEX 4.2  I would recommend using apex.server.process which is the documented replacement of the officially undocumented htmldb_Get.
    In the documentation it is set that the first parameter is the ajaxidentifier but it actually is the process name.
    The data object would be something like
    var lData ={f01 : get_value_array('f01')}
    Where get_value_array is
    function get_value_array(pColumnName) {
      var l_values =[];
      apex.jQuery('[name="'+pColumnName+'"]').each(
       function(){
        var l_value;
        l_value = apex.item(this.id).getValue();
        l_values.push(l_value);
      return l_values
    For a working example see this demo.
    Nicolette

  • Calling packaged procedure from a URL link

    I have created a custom APEX application the will allow us to dynamically build help screens for the pages we create with APEX.
    In doing this I have created a procedure within a package called "comi_help_util.show_help".
    This procedure uses the "htp.p" standard procedure to create a dynamic web page from data stored inside my help tables.
    I want to place a "Help" link in the Navigation Bar which will call the custom procedure, pass the APP_ID and APP_PAGE_ID and popup in a new window.
    I tried doing something like the Help link in APEX.
    javascript:popupURL('comi_help_util.show_help?p_application_id=&APP_ID.&p_page_id=&APP_PAGE_ID.');
    Unfortunately, I get "HTTP 404 - Web page cannot be found" error.
    I know I could probably call a page within my APEX application from my custom Help link which would then call my custom procedure.
    However, this means I would have to put a page within every application I want to use this on.
    I believe the call to the procedure directly would be cleaner and easier to implement, if I can get this working on my first app.
    I have never called a procedure thru a URL link or the javascript:popupURL and, try as I might, cannot search for the right keywords in the APEX forum or the Web.
    Any help would be appreciated.
    THANKS
    Raymond

    Hi Scott,
    >> Time for new glasses ...
    You are probably right, but regardless, I was referring to Raymond’s first post (and I should have made it clear). I noted that I believe your JavaScript statement is correct, I just can’t see the difference between it and the OP first statement, where, as far as I can see, he also used question mark (?) to mark parameters, and ampersand (&) to concatenate them. Still he received a 404 error. What am I missing there?
    Thanks,
    Arie.
    Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

  • PLSQL portlet - problem calling stored procedure -

    Good day folks. My portal version 10.1.2. I have a dynamic page with multiple rows. For simplicity, example here has two columns => id and value. The initial dilemma - The stored procedure specified in the action attribute of the <form> tag has to have parameters that match in name and count to the fields on the html form. But, the number of rows is variable on the form. I currently use pl/sql to generate the page. I have two forms in the html - form A has two static fields id and value, with an action attribute of the stored procedure I want to run. The second html form is form B. It has id_1, value_1, id_2, value_2, id_3, value_3 and so on with a variable number of rows. SO, when the user clicks the "Submit" button at the bnottom of the page, I call a javascript passing in the number of rows. I then loop through the Form B, and for each row of data, I do a submit of Form A. My goal is to run the stored procedure in the database for each row of data in Form B. I use Form A to accomodate the requirement that the stored procedure has to match in name and number the parameters inthe form.
    This is to avoid an update button on each row of data, also.
    The problem - in my javascript, I set the values of Form A to the values from Form B correctly. However, only the last rowis successful in running the procedure. For example, if I have 3 rows in Form B, I want to submit form A 3 times, but, it only seems to submit once for row #3. The weird thing is if I put an alert message after the document.formA.submit(); command, the stored procedure is successfully called for each row in form B, but when I remove the alert, only the last row successfully calls the procedure!
    Thanks in advance if anybody has any ideas -
    Kent

    Let's continue the example of 3 rows.
    It sounds like that you submit the form 3 times in quick succession, and so before the Action for Form A has had time to run and respond for the first row, the second row has been submitted, and therefore the web page will stop trying to display the results from the submit of Row 1 (by this I mean it'll stop the http request, if you do this quick enough then the back-end function won't run). Then the same thing happens to Row 2's submit when Row 3 starts.
    What it sounds like you need to do is to use only 2 parameters, but repeat them on the HTML page, when the submit is run it's passed to oracle as a type 'owa_util.vc_arr'. There is a more comprehensive solution to this problem in another thread:
    passing variable number of arguments in a stored procedure
    Please note though that you have to be careful of the situations where your form only has one row to submit to the oracle function, in this case the data type of the parameter will be a VARCHAR2 rather than a owa_util.vc_arr. The solution to this problem is to always have a an extra dummy parameter which is empty and you skip over it during your processing. (Thought I'd better include this information in case you ran into this problem).
    Hope this helps.
    Cheers,
    Ron.

Maybe you are looking for