Passing variable number of arguments in a stored procedure

Hi Team,
i am facing a problem. I have a dynamic form which contains some checkboxes. The number of checkboxes are dynamically generated on querying the database. On the form submission i want to call a stored procedure that will update the values in the database. i want to know that is there any way to handle variable number of arguments in the stored procedure or can i get the variables through some session context and use it in my stored procedure.
Any help is greatly appreciated.
Thanks&Regards
Saurabh Jain

Hi Saurabh,
The method in which stored procedures are called on form submit is something as follows.
Let us take your scenario of a form which has multiple checkboxes and a submit button. On clicking the submit button, this form data is submitted using either get or post. The form's submit action invokes a procedure.
The HTML form code will look something like this..
htp.formOpen( curl => 'URL /myProcedure',
cmethod => 'post' );
htp.formCheckbox( cname => 'myCheckbox'
cvalue => 'A');
htp.formCheckbox( cname => 'myCheckbox'
cvalue => 'B');
htp.formCheckbox( cname => 'myCheckbox'
cvalue => 'C');
htp.formSubmit( cname => 'myButton',
cvalue => 'OK');
Now, whenever the submit button is clicked, all these form values are passed to our stored procedure 'myProcedure'.
"myProcedure" looks something like this.
procedure myProcedure
myCheckbox IN sys.owa_util.vc_arr,
myButton IN VARCHAR2
is
begin
end myProcedure;
The point to be noted here is that the name of the variable being passed in the procedure is the same as the name of the HTML element being created in the HTML form. So, there is a direct mapping between the elements in the HTML form and the procedure parameters.
Another noteworthy point is that since you have multiple checkboxes in your HTML form, it is impractical to name all the checkboxes differently and then pass those many parameters to your procedure (Imagine a scenario where there are a hundred check-boxes in an HTML form!). So portal allows you to give the same name (cname) to all the checkboxes in your HTML form, and if multiple checkboxes are checked, it will return all the checkbox values in an array (Note the usage of "myCheckbox IN sys.owa_util.vc_arr" in myProcedure).
You can check out this link for more information.
Re: retrieving data from fields
Thanks,
Ashish.

Similar Messages

  • Passing Variable Number of Parameters to Cobol Stored Procedure

    Hi. I have a web front end that needs to access several different tables via Cobol stored procedures. It seems simple enough to call the stored procedures straight away (DAO Pattern perhaps?) but my boss is insistent on having an intermediate Cobol program that decides which table to access. I think he at a bigger picture than I can see.
    The problem lies in the number of parameters that need to be passed to the stored procedures; some need 3, others needs 5, a few need 4. The only two solutions that I can think of are to pass EVERYTHING (we're talking 50 parameters or so) to the intermediate stored procedure and then pulling only what is needed from that data set to access the desired table. Solution number two involves passing everything to a temp table and then pulling what is needed from it. The former solution seems a little cleaner but still involves passing a lot of parameters. If Cobol could handle some sort of dynamic memory allocation (Vector) there seems to be a possible solution there. Though, as far as I know, that isn't possible.
    Any ideas are much appreciated.
    Thanks in advance,
    Chris

    Hi Saurabh,
    The method in which stored procedures are called on form submit is something as follows.
    Let us take your scenario of a form which has multiple checkboxes and a submit button. On clicking the submit button, this form data is submitted using either get or post. The form's submit action invokes a procedure.
    The HTML form code will look something like this..
    htp.formOpen( curl => 'URL /myProcedure',
    cmethod => 'post' );
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'A');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'B');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'C');
    htp.formSubmit( cname => 'myButton',
    cvalue => 'OK');
    Now, whenever the submit button is clicked, all these form values are passed to our stored procedure 'myProcedure'.
    "myProcedure" looks something like this.
    procedure myProcedure
    myCheckbox IN sys.owa_util.vc_arr,
    myButton IN VARCHAR2
    is
    begin
    end myProcedure;
    The point to be noted here is that the name of the variable being passed in the procedure is the same as the name of the HTML element being created in the HTML form. So, there is a direct mapping between the elements in the HTML form and the procedure parameters.
    Another noteworthy point is that since you have multiple checkboxes in your HTML form, it is impractical to name all the checkboxes differently and then pass those many parameters to your procedure (Imagine a scenario where there are a hundred check-boxes in an HTML form!). So portal allows you to give the same name (cname) to all the checkboxes in your HTML form, and if multiple checkboxes are checked, it will return all the checkbox values in an array (Note the usage of "myCheckbox IN sys.owa_util.vc_arr" in myProcedure).
    You can check out this link for more information.
    Re: retrieving data from fields
    Thanks,
    Ashish.

  • Passing array as a argument in the Stored Procedure/Function

    Hello Friends,
    I need a help, i Want one stored proedure/Function which take array as a argument and return an array also.
    and the size of array should not be fixed.
    I don't want to use Varray because for this I have to specified its size first.
    I think Associative arry will work( For dynamic size) but I am not able to run it .
    Is Associative arry(Index by Pls_Integer) support JDBC?
    If yes, plz give me some clue. I have found some information of associative array in this url
    http://www.oracle.com/technology/oramag/oracle/07-jan/o17odp.html
    But I am not able to run this package through SQL and also not able to connect it through JDBC.
    Is there any other alternative solution?
    Thanks & Regards,
    manish Kumar

    This is my table structure :
    SQL> desc jobs
    Name Null? Type
    JOB_ID      NOT NULL VARCHAR2(10)
    JOB_TITLE      NOT NULL VARCHAR2(35)
    MIN_SALARY NUMBER(6)
    MAX_SALARY NUMBER(6)
    My Requirement is, User will enter the above field value in the form of array. I need to store these value and after manupulating this I will return that value also.
    Here I am using procedure just for testing purpuse.
    In my case I will take one array argumentlike JOB_ID and after manupulating these data I will return that array value.
    I am also not able to run this example through SQL.
    Can U give me exact code for running this prog.
    create or replace package associative_array as
    -- define an associative array type for each column in the jobs table
    type t_job_id is table of jobs.job_id%type index by pls_integer;
    type t_job_title is table of jobs.job_title%type index by pls_integer;
    type t_min_salary is table of jobs.min_salary%type index by pls_integer;
    type t_max_salary is table of jobs.max_salary%type index by pls_integer;
    -- define the procedure that will perform the array insert
    procedure array_insert (p_job_id in t_job_id,
    p_job_title in t_job_title,
    p_min_salary in t_min_salary,
    p_max_salary in t_max_salary);
    end associative_array;
    create or replace package body associative_array as
    -- implement the procedure that will perform the array insert
    procedure array_insert (p_job_id in t_job_id,
    p_job_title in t_job_title,
    p_min_salary in t_min_salary,
    p_max_salary in t_max_salary) is
    begin
    forall i in p_job_id.first..p_job_id.last
    insert into jobs (job_id,
    job_title,
    min_salary,
    max_salary)
    values (p_job_id(i),
    p_job_title(i),
    p_min_salary(i),
    p_max_salary(i));
    end array_insert;
    end associative_array;
    Regards,
    manish Kumar

  • Can we write function with variable number of argument

    Hi
    Can anybody tell that can we pass variable number of arguments to a function in oracle 10gR2.
    As in function decode we can pass variable no. of arguments upto 255 arguments, similarly can we creat a function which accept any no. of variables.

    I'm not sure that this is what you were asking about, but depending on the logic you want to implement, you can declare the maximum possible number of parameters to your function, give them default values, and then pass to your func as many parameters as you want:
    SQL> create or replace function test(p_a number:=null, p_b number:=null) return varchar2 is
      2    Result varchar2(100);
      3  begin
      4    result:='a='||p_a||', b='||p_b;
      5    return(Result);
      6  end test;
      7  /
    Function created
    SQL> select test() from dual;
    TEST()
    a=, b=
    SQL> select test(1) from dual;
    TEST(1)
    a=1, b=
    SQL> select test(1,2) from dual;
    TEST(1,2)
    a=1, b=2
    SQL> drop function test;
    Function dropped
    SQL>

  • Variable number of arguments in procedure PL/SQL

    Hello everyone,
    I have a "simple" question : can a procedure PL/SQL take a variable number of arguments ?
    In my case, the procedure is called by the submit button of a form, and the form has variable number of inputs...
    Thanks you !

    862447 wrote:
    I have a "simple" question : can a procedure PL/SQL take a variable number of arguments ?No. Not in the style of Pascal and C/C++. E.g. int printf( char * format, … ) in C using va_list.
    In my case, the procedure is called by the submit button of a form, and the form has variable number of inputs...There are a couple of merhods.
    Code a fixed number of parameters in the procedure signature. Assign defaults to these. The caller can now select which parameters from the fixed list to use and which not.
    Create a structure. For example, having a 100 parameters in a signature is something I will call plain stupidity. This creates usability issues, maintenance issues and even performance issues. And debugging will be a nightmare. So instead create a structure (aka record in the PL/SQL language or an object using the SQL language) - where this structure describes (in a structured and logical way) the list of parameters.
    Neither of these method however allows the caller to pass a variable number parameters - the parameter signature is fixed. It has a fixed number of defined parameters.
    So the only way to simulate a variable parameter signature is to use a collection. The collection itself is of course a single parameter passed. But it can have 0 elements. It can have a 1000 elements. And similar to a va_list in C/C++, the procedure can iterate through the data passed via the parameter by the caller.
    Simple example:
    //-- define the collection type, e.g. a collection of strings
    create or replace type TStrings is table of varchar2(4000);The procedure's signature:
    --// passing by referencing and not value should be considered
    create or replace procedure FooProc( param TStrings ) is ..And to call this procedure with variable parameters:
    --// calling it with 2 param value
    FooProc( TString('123','testing') );
    --// calling it with 5 param values
    FooProc( TString('p1','p2','p3','p4','p5') );

  • Variable number of arguments in C functions

    Hello. I know how to achieve creating a function that accepts a variable number of arguments. For example:
    #include <stdio.h>
    #include <stdarg.h>
    int add (int x, ...);
    int main (int argc, const char * argv[])
    int result = add(3, 5, 3, 7);
    printf("%d", result);
    return 0;
    int add (int x, ...)
    va_list argList;
    va_start(argList, x);
    int sum = 0;
    int i;
    for (i = 0; i < x; ++i)
    sum += va_arg(argList, int);
    va_end(argList);
    return sum;
    The first argument, x, is sent to the function and represents how many additional optional arguments will be sent to the function (3 in the above example). Then, the definition of the add function totals those remaining (3) arguments, returning a value of (in this case) 15, which main then prints to the console. Simple enough, but here's my question:
    What if I want to achieve this same optional arguments concept without having to send the function the number of optional arguments it will be accepting. For example, the printf() function takes an optional number of arguments, and nowhere there do you have to specify an extra argument that represents the number of additional optional arguments being passed (unless maybe the number of formatting specifiers in the first argument determines this number). Can this be done? Does anyone have any input here? Thanks in advance.

    Hi Tron -
    I looked over my first response again, and it needs to be corrected. Fortunately Bob and Hansz straightened everything out nicely, but I still need to fix my post:
    RayNewbie wrote:
    Yes, the macros are designed to walk a list of args when neither the number of args or their type is known.
    The above should have said. "The macros are designed to walk a list of args when neither the number of args or their type is known _at compile time_".
    If I may both paraphrase and focus your original question, I think you wanted to know if there was any way the function could run without knowing the number of args to expect. The answer to this question is "No". In fact at runtime, the function must know both the number of args and the type of each.
    Tron55555 wrote:
    ... the printf() function takes an optional number of arguments, and nowhere there do you have to specify an extra argument that represents the number of additional optional arguments being passed (unless maybe the number of formatting specifiers in the first argument determines this number).
    As both Bob and Hansz have explained, the underlined statement is correct. Similarly, the example from the manual gives the number and types of the args in the first string arg.
    Hansz also included an alternative to an explicit count or format string, which is to terminate the arg list with some pre-specified value (this is sometimes called a "sentinel" value. However when using a sentinel, the called function must know the data types. For example, you could never simply terminate the args with a sentinel and then pass a double followed by an int. The combined length of these args is 8 + 4 => 12 bytes, so unless the function knew which type was first at compile time, it wouldn't be possible to determine whether the list was 4+8 or 8+4 at runtime.
    If you're interested in knowing why a variable arg function is limited in this way, or in fact how any C function finds its args, its parameters, and how to return to the calling function, you might want to do some reading about the "stack frame". You can learn the concept without getting into any assembler code. Here's an article that might be good to start with: [http://en.citizendium.org/wiki/Stack_frame].
    After you have some familiarity with the stack frame, take a look at the expansions of the stdarg macros and see if you can figure out how they work, especially how va_arg walks down the stack, and what info is required for a successful trip. Actually, I don't think you can find these expansions in the stdarg.h file for Darwin; it looks like the #defines point to built-in implementations, so here are some typical, but simplified defs:
    // these macros aren't usable; necessary type casts have been removed for clarity
    typedef va_list char*;
    #define va_start(ap,arg1) ap = &arg1 + sizeof(arg1)
    #define va_arg(ap,type) *(ap += sizeof(type))
    #define va_end(ap) 0
    Note that I"m trusting you not to start asking questions about the stack or the above macros until you've studied how a stack works and how the C stack frame works in particular.
    - Ray

  • Variable number of arguments in DML

    In my OLAP DML program, I need to take variable number of arguments. I took the number of inputs as one argument and then tried to take succeeding inputs as arguments in a while-loop, but got an error saying "All ARGUMENT statements must precede the first non-declarative"
    Can you suggest a way in which I can take variable number of arguments in an OLAP DML program?

    This any use:
    DEFINE ARG.TEST PROGRAM
    blank
    shw joinchars('Number of Arguments Passed: ' ARGCOUNT)
    blank
    blank
    shw joinchars('Argument 1: ' arg(1))
    shw joinchars('Argument 2: ' arg(2))
    shw joinchars('Argument 3: ' arg(3))
    shw joinchars('Argument 4: ' arg(4))
    blank

  • How to pass variable number of parameters to a FORM.

    Hi,
    What is the correct syntax to pass variable number of parameters to a subroutine?
    PERFORM TEST TABLES BRETURN USING TEST_NAME CHANGING MY_OUTPUT.
    FORM TEST TABLES RETURN STRUCTURE BAPIRET2
              ITAB STRUCTURE ITABLE_LINE OPTIONAL
              USING VALUE(NAME) TYPE STRING
              CHANGING VALUE(OUTPUT) TYPE STRING.
    The above code does not work. How can we specify an optional parameter?
    Thanks and Regards,
    Sheetal
    Message was edited by: Sheetal Pisolkar

    Hi,
    I am trying to use a subroutine instead of function.A FUNCTION understands optional keyword.
    How can this work for a FORM?
    CALL FUNCTION 'TEST'
         EXPORTING
              MY_OUTPUT = 'output'
         IMPORTING
              TEST_NAME = 'mytest'.     
    FUNCTION TEST
    *     EXPORTING
    *          VALUE(OUTPUT) TYPE STRING
    *     IMPORTING
    *          VALUE(NAME) TYPE STRING
    *     TABLES
    *          RETURN STRUCTURE BAPIRET2 OPTIONAL
    *          ITAB STRUCTURE ITABLE_LINE OPTIONAL          
    ENDFUNCTION.
    PERFORM TEST USING TEST_NAME CHANGING MY_OUTPUT.
    FORM TEST TABLES RETURN STRUCTURE BAPIRET2 OPTIONAL
    ITAB STRUCTURE ITABLE_LINE OPTIONAL
    USING VALUE(NAME) TYPE STRING
    CHANGING VALUE(OUTPUT) TYPE STRING.
    ENDFORM.
    Is this be possible?
    Thanks
    Sheetal.

  • Passing collection parameters from/to Oracle 8i stored procedure to/from Weblogic java program

    Environment- Oracle DB 8.1.7 (Sun) - JDBC OCI 8.1.7 - Application Server (WebLogic 6.0 or 6.1)QuestionHow to pass oracle collection data types from PL/SQL stored procedures to Weblogic java program as in/out stored procedures parameters. I am hitting oracle error 2006 unidentified data type trying to pass the following data types:-o java.sql.Structo java.sql.Arrayo oracle.sql.STRUCTo oracle.sql.ARRAYo oracle.jdbc2.Structo oracle.jdbc2.Arrayo any class implemented oracle.jdbc2.SQLData or oracle.sql.CustomDatumInformationAbout PL/SQL stored procedure limitation which only affects the out argument types of stored procedures calledusing Java on the client side. Whether Java methods cannot have IN arguments of Oracle 8 object or collection type meaning that Java methods used to implement stored procedures cannot have arguments of the following types:o java.sql.Structo java.sql.Arrayo oracle.sql.STRUCTo oracle.sql.ARRAYo oracle.jdbc2.Structo oracle.jdbc2.Arrayo any class implemented oracle.jdbc2.SQLData or oracle.sql.CustomDatum

    this is becoming a mejor problem for me.And are you storing it as a blob?
    Oracle doesn't take varchars that big.
    And isn't LONG a deprecated field type for Oracle?
    From the Oracle docs......
    http://download-west.oracle.com/docs/cd/B13789_01/server.101/b10759/sql_elements001.htm#sthref164
    Oracle strongly recommends that you convert LONG RAW columns to binary LOB (BLOB) columns. LOB columns are subject to far fewer restrictions than LONG columns. See TO_LOB for more information.

  • Pass a null value to a JDBC stored procedure call?

    pass a null value to a JDBC stored procedure call? Is this even possible? My DBA gave me a procedure to call that sometimes requires a null value. I don't think this is even possible.

    do you mind tell me how to resolve your problem?i using the setnull method,but it doesn't work.

  • Pass a jdbc resultset in to a Stored Procedure

    Any answer to the following question would be highly appreciated:
    How can we pass a jdbc resultset in to a Stored Procedure?
    Thanks.

    You could use Oracle's ANYDATASET type or declare schema TYPEs to support passing the data in a known structure. See "Working with Oracle Collections" in the "JDBC Developer's Guide and Reference" on technet.

  • Is it possible to pass TABLE as the output parameter in stored procedure

    Hey Experts,
      Is it possible to pass TABLE as the output parameter in stored procedure.
    eg
    create procedure spGetData
    @tableName as TABLE(intValue INT NOT NUL)
    as 

    You can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
    some limitations with these methods:
    http://technet.microsoft.com/en-us/library/ms188427.aspx
    In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
    exec sp_serveroption @server = 'PRODSVR\SQL2012'
    ,@optname = 'DATA ACCESS'
    ,@optvalue = 'TRUE'
    LINK: http://www.sqlusa.com/bestpractices/select-into/
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • How many number of input/output arguments allowed in Stored procedure

    Please let me know how may input and output arguments are allowed in Oracle stored procedure.
    I wan't to writer one generic SP and for that I need to know the limitation on the number of arguments. I am using Oracle 8.0.5.

    The output from the BPEL process will be in XML format.
    Your requirement is not clear, please state it properly what are you trying to do.
    -Yatan

  • Arguments in a stored procedure.

    Hi,
    Please can you tell me:
    What is the maximum size of a VARCHAR2 parameter as passed as an argument in an Oracle stored procedure.
    e.g.
    CREATE OR REPLACE PROCEDURE test (test_param VARCHAR2)
    IS
    The maximum string length of test_param is?
    Thanks,
    Duncan

    In the declaration of a stored procedure only the argument types are specified, not the sizes or lengthsIt's annoying that we cannot enforce sizings even if we use a SUBTYPE to declare a parameter in a procedure's signature: it can only be done inside the procedure itself....
    SQL> create or replace package my_subtypes as
      2     subtype ltd_string is varchar2(10);
      3  end;
      4  /
    Package created.
    SQL> create or replace function my_f
      2      (p_in in my_subtypes.ltd_string)
      3      return number
      4  as
      5  begin
      6      return length(p_in);
      7  end;
      8  /
    Function created.
    SQL> select my_f(to_char(sysdate, 'dd-mon-yyyy hh24:mi:ss'))
      2  from dual
      3  /
    MY_F(TO_CHAR(SYSDATE,'DD-MON-YYYYHH24:MI:SS'))
                                                20
    SQL> create or replace function my_f
      2      (p_in in my_subtypes.ltd_string)
      3      return number
      4  as
      5      lv my_subtypes.ltd_string;
      6  begin
      7      lv := p_in;
      8      return length(lv);
      9  end;
    10  /
    Function created.
    SQL> select my_f(to_char(sysdate, 'dd-mon-yyyy hh24:mi:ss'))
      2  from dual
      3  /
    select my_f(to_char(sysdate, 'dd-mon-yyyy hh24:mi:ss'))
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "APC.MY_F", line 7
    SQL>Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • How to get list of parameters or arguments for a stored procedure

    Hi,
    Is there a way we can get the list of arguments or parameters for a stored procedure through Data Dictionary?
    I mean the way oracle has Meta Data tables like user_tables/dba_tables, user_triggers/dba_triggers through which we can get information about tables, triggers etc, in the same way is there a way in oracle so that we can get information about a procedure like what kind of arguments need to be passed, are they IN or OUT parameters, and what is their Data Types?
    I could find there is one View dba_procedures, but it does not give any information about the arguments a procedure takes.
    Thanks,
    Makrand
    Thansk

    or
    SQL> desc Raisesal ;
    PROCEDURE Raisesal
    Argument Name                  Type                    In/Out Default?
    ID                             NUMBER(4)               IN
    PERCENT                        NUMBER                  IN

Maybe you are looking for