Passing array to the procedure in parameter

Hi
I tried the following code,
Where my aim is to split the comma separated values and insert into an array, and then pass that array to another procedure in a package
CREATE OR REPLACE PACKAGE PAK_SPLIT_TEST AS
PROCEDURE PROC_SPLIT(IN_LIST  VARCHAR2) ;
END;
CREATE OR REPLACE PACKAGE PAK_SPLIT_TEST AS
PROCEDURE PROC_SPLIT(IN_LIST  VARCHAR2) ;
END;
CREATE OR REPLACE PACKAGE PAK_SPLIT_TEST
AS
   PROCEDURE PROC_SPLIT (IN_LIST VARCHAR2);
END;
CREATE OR REPLACE PACKAGE BODY PAK_SPLIT_TEST
AS
   PROCEDURE PROC_REM_LIST (p_array l_data)
   IS
   BEGIN
      FOR i IN 1 .. p_array.COUNT
      LOOP
         DBMS_OUTPUT.put_line (p_array (i));
      END LOOP;
   END;
   PROCEDURE PROC_SPLIT (IN_LIST VARCHAR2)
   IS
      TYPE SPLIT_array IS TABLE OF VARCHAR2 (4000)
                             INDEX BY BINARY_INTEGER;
      l_data   SPLIT_array;
      l_txt    LONG := '100,200,300,400,500,600';
      l_str    LONG := IN_LIST || ',';
      l_n      NUMBER;
   BEGIN
      BEGIN
         l_data.delete;
         LOOP
            l_n := INSTR (l_str, ',');
            EXIT WHEN NVL (l_n, 0) = 0;
            l_data (l_data.COUNT + 1) := SUBSTR (l_str, 1, l_n - 1);
            l_str := SUBSTR (l_str, l_n + 1);
         END LOOP;
         PROC_REM_LIST (l_data);
      END;
   END;
SELECT *FROM USER_ERRORSI'm getting the following error at line no. 30
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
   begin end function package pragma procedure formCould you please help me in this
Thanks,
Smile

Give this a shot:
CREATE OR REPLACE PACKAGE BODY PAK_SPLIT_TEST
AS
      TYPE SPLIT_array IS TABLE OF VARCHAR2 (4000)
                             INDEX BY BINARY_INTEGER;
   PROCEDURE PROC_REM_LIST (p_array SPLIT_array)
   IS
   BEGIN
      FOR i IN 1 .. p_array.COUNT
      LOOP
         DBMS_OUTPUT.put_line (p_array (i));
      END LOOP;
   END;
   PROCEDURE PROC_SPLIT (IN_LIST VARCHAR2)
   IS
      l_data   SPLIT_array;
      l_txt    LONG := '100,200,300,400,500,600';
      l_str    LONG := IN_LIST || ',';
      l_n      NUMBER;
   BEGIN
      BEGIN
         l_data.delete;
         LOOP
            l_n := INSTR (l_str, ',');
            EXIT WHEN NVL (l_n, 0) = 0;
            l_data (l_data.COUNT + 1) := SUBSTR (l_str, 1, l_n - 1);
            l_str := SUBSTR (l_str, l_n + 1);
         END LOOP;
         PROC_REM_LIST (l_data);
      END;
   END;
END pak_split_test;
/PROC_REM_LIST was expecting a PL/SQL type of L_DATA. You have not defined that type anywhere (e.g. in your package spec, body, or in SQL). I move the declaration from PROC_SPLIT to your package body and it compiles.
Hope this helps!

Similar Messages

  • How to pass ARRAY to Oracle Procedure

    Hi
    We are using BC4J with JSP in our project. We need to send an Array to the procedure.
    Could somebody provide some info as how this can be achieved.

    A while back, I used a SQLJ client to call a Java (also SQLJ) stored procedure and I needed to pass an array of strings to the procedure. I did something like this:
    Java Class that was loaded in DB:
    public class MyClass
    // method that the stored procedure uses
    public static void CALL_DOSTUFF(String a,
    oracle.sql.ARRAY b,
    oracle.sql.ARRAY c)
    String[] bb = (String[])b.getArray();
    String[] cc = (String[])c.getArray();
    doStuff(a,bb,cc);
    public static void doStuff(String a,
    String[] b,
    String[] c)
    // process the input
    In the database I added the type:
    create or replace type STR_ARRAY as table of varchar2(20);
    and the procedure:
    create or replace procedure CALL_DOSTUFF(a varchar2,
    b STR_ARRAY,
    c STR_ARRAY)
    as
    language java
    name 'MyClass.CALL_DOSTUFF(java.lang.String,
    oracle.sql.ARRAY,
    oracle.sql.ARRAY)';
    I then used jpub to publish a STR_ARRAY.java file. I compiled this and used it with my SQLJ client to call to the stored procedure. The STR_ARRAY constructor takes a String[], so you do something like this in the SQLJ client:
    String x = "X";
    String y = {"y1","y2"};
    String z = {"z1","z2"};
    STR_ARRAY y1 = new STR_ARRAY(y);
    STR_ARRAY z1 = new STR_ARRAY(z);
    #sql {CALL CALL_DOSTUFF(:x,:y1,:z1)};
    Hope this helps.

  • Trying to pass array to stored procedure in a loop using bind variable

    All,
    I'm having trouble figuring out if I can do the following:
    I have a stored procedure as follows:
    create procedure enque_f826_utility_q (inpayload IN f826_utility_payload, msgid out RAW) is
    enqopt dbms_aq.enqueue_options_t;
    mprop dbms_aq.message_properties_t;
    begin
    dbms_aq.enqueue(queue_name=>'f826_utility_queue',
    enqueue_options=>enqopt,
    message_properties=>mprop,
    payload=>inpayload,
    msgid=>msgid);
    end;
    The above compiles cleanly.
    The first parameter "inpayload" a database type something like the following:
    create or replace type f826_utility_payload as object
    2 (
    3 YEAR NUMBER(4,0),
    4 MONTH NUMBER(2,0),
    83 MUSTHAVE CHAR(1)
    84 );
    I'd like to call the stored procedure enque_f826_utility_q in a loop passing to it
    each time, new values in the inpayload parameter.
    My questions are:
    First, I'm not sure in php, how to construct the first parameter which is a database type.
    Can I just make an associative array variable with the keys of the array the same as the columns of the database type shown above and then pass that array to the stored procedure?
    Second, is it possible to parse a statement that calls the enque_f826_utility_q procedure using bind variables and then execute the call to the stored procedure in a loop passing new bind variables each time?
    I've tried something like the following but it's not working:
    $conn = oci_pconnect (....);
    $stmt = "select * from f826_utility";
    $stid = oci_parse($conn, $sqlstmt);
    $r = oci_execute($stid, OCI_DEFAULT);
    $row = array();
    $msgid = "";
    $enqstmt = "call enque_f826_utility_q(:RID,:MID)";
    $enqstid = oci_parse($conn, $sqlstmt);
    oci_bind_by_name($enqstid, ":RID", $row); /* line 57 */
    oci_bind_by_name($enqstid, ":MID", $msgid);
    while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC))
    ++$rowcnt;
    if (! oci_execute($enqstid)) /* line 65 */
    echo "Error";
    exit;
    When I run this, I get the following:
    PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
    ine 57
    Entering loop to process records from F826_UTIITY table
    PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
    ine 65
    PHP Warning: oci_execute(): ORA-06553: PLS-306: wrong number or types of argume
    nts in call to 'ENQUE_F826_UTILITY_Q' in C:\Temp\enqueue_f826_utility.php on lin
    e 65
    PHP Notice: Undefined variable: msgnum in C:\Temp\enqueue_f826_utility.php on l
    ine 68
    Error during oci_execute of statement select * from F826_UTILITY
    Exiting!

    Thanks for the reply.
    I took a look at this article. What it appears to describe is
    a calling a stored procedure that takes a collection type which is an array.
    Does anyone from Oracle know if I can pass other database type definitions to a stored procedure from PHP?
    I have a type defined in my database similar to the following which is not
    an array but a record of various fields. This type corresponds to a payload
    of an advanced queue payload type. I have a stored procedure which will take as it's input, a payload type of this structure and then enqueue it to a queue.
    So I want to be able to pass a database type similar to the following type definition from within PHP. Can anyone from Oracle verify whether or not this is possible?
    create or replace type f826_utility_payload as object
    YEAR NUMBER(4,0),
    MONTH NUMBER(2,0),
    UTILITY_ID NUMBER(10,0),
    SUBMIT_FAIL_BY VARCHAR2(30),
    MUSTHAVE CHAR(1)
    );

  • Pass DB Link in procedure as parameter.

    Hi,
    I am using ORACLE Database 11g .
    I have a procedure in which i am already passing some parameters. The procedure contains few statements in which it has to refer to specific user for getting the data. So we use DB Link. As which user to connect is not sure so the DB LINK is also not constant. That is why i want to pass the DB link as a parameter to procedure. But if i don't give the db link name in procedure the procedure will not compile.
    A sample of my code is as follows :-
    create or replace procedure P_GET_TABLES(V_DBLINK in varchar2)
    as
    FOR I in (select s.TABLE_NAME
                    from user_tables@V_DBLINK s, dba_tables d          --- Obviously it gives me error that table does not exists.Due to variable V_DBLINK
                   where d.table_name = s.TABLE_NAME
                     and s.TABLE_NAME != 'ERROR_LOG'
                     and d.owner = V_SOURCE_SCHEMA_NAME
                  union (select s.TABLE_NAME
                          from user_tables@V_DBLINK s
                        minus
                        select TABLE_NAME
                          from dba_tables d
                         where owner = V_SOURCE_SCHEMA_NAME)) Loop
    -- other code for the process.....
    END LOOP;
    END;
    /Is their any method that i can pass a compiled procedure DB LINK as parameter or at run-time. ??
    Thanks in advance.

    VIRU wrote:
    Its a request can you just do the same thing with the FOR LOOP given by me in the first post. It will look something like this:
    create or replace procedure P_GET_TABLES
        (V_DBLINK in varchar2
          , V_SOURCE_SCHEMA_NAME  in varchar2)
    as
        rc sys_refcursor;
        l_table_name all_tables.table_name%type;
    begin
        open rc for 'select s.table_name
                    from user_tables@'||V_DBLINK||' s, dba_tables d
                   where d.table_name = s.table_name
                     and s.table_name != ''ERROR_LOG''
                     and d.owner = :1
                  union (select s.table_name
                          from user_tables@'||V_DBLINK||' s
                        minus
                        select table_name
                          from dba_tables d
                         where owner = :1)'
        using V_SOURCE_SCHEMA_NAME, V_SOURCE_SCHEMA_NAME;
       loop
            fetch rc into l_table_name;
            exit when rc%notfound;
            --  do your processing here....
       end loop;
       close rc;
    end P_GET_TABLES;
    /The Oracle online documentation covers dynamic SQL quite comprehensively. [url http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/dynamic.htm#i14500]Find out more.
    I think you have some confusion with the data dictionary views you're using, USER_TABLES@remote_db will look for tables in a schema with the same name as the current user in the local database. The current user in the local database has the privileges to read the DBA_ level views in te local data dictionary but apparently isn't the account owning the tables in the remote database.
    Is that right? It sounds like a mess. I have to [url https://forums.oracle.com/forums/thread.jspa?messageID=10062119#10062119]agree with Billy that you might be trying to solve the wrong problem. Perhaps you need better configuration/release management processes?
    Cheers, APC
    Edited by: APC on Jan 2, 2012 9:52 AM

  • How to pass array in the url of the servlet

    Hi Friends,
    How can i pass an array in the URL that calls a servlet. For instance,I have this in my servlet rite now:
            MyClass obj = new MyClass();
            String[] args = {"-opt1","-opt2","file1","file2","file3"};
            obj.main(args);I want that the "args" should come in the URL call,because some php application would be calling this, for instance:
    http://localhost:8080/MyProject/MyServlet?args=somearray
          MyClass obj = new MyClass();
          String[] arg = request.getParameter("args");
          obj.main(arg);Please help..I would really appreciate it.
    Thanks

    Sorry,needed to edit this,I am getting some problem,please help if you can:
    I call the java class from the servlet as shown above,and it executes fine but only for the first time...after that the tomcat automatically shuts down .....can someone explain me why????
    How can i get the execution control back to the servlet ..for example:
      System.out.println("Before execution..");
      MyClass obj = new MyClass();
      String[] arg = request.getParameter("args");
      obj.main(arg);
      System.out.println("After execution..");prints only "before execution..."..so can someone please tell me how can i bring the control back to the servlet...
    Thanks
    Message was edited by:
    java80

  • Passing Arrays to the DataGrid Component

    How's it going my peoples? I'm having some difficulties
    passing Arrays into a DataGrid Component. It just doesnt seem to
    work for me. Anyone have any ideas on the best way of doing this?
    Thank you in advance.

    We have Our site build using odp.net but suddenly it stoped working on the production server. MS Provider is working fine in that case. so we want to have one copy of solution with MS provider as backup copy so in future if any failure occurs to odp.net we can use this copy. So for that I need to know how to pass arrays to oracle using MS Provider.
    Regards,
    Suresh

  • Passing array to stored proc as parameter

    Hi,
    I want to pass an array from my .Net application to oracle as a parameter to one of my stored proc. The signature of my SP looks like.
    SP_Name(counter int, table_name varchar, log_values logs)
    --(where logs is a varray of type varchar(100)
    How can i pass an array of logs from .Net to this stored proc using ODP.Net?
    Please help.

    You should have an example on your hard drive in
    %OracleHome%\ODP.NET\samples\AssocArray
    Cheers

  • Pass Array to Database Procedure

    Hi,
    I've a JSP in which I can collect the parameters as array. I, then, want to pass on this array to a database prodecure/function. How can I do that.
    I already have tried Steve's ArrayOfStringDomain example. (ArrayOfStringDomain) and it didn't work.
    Can someone please help me.
    Thanks,
    Jatinder

    Hi Jatinder,
    For information on passing an array to a stored procedure refer here.
    Hope this helps.
    Sujatha.

  • Pass array to oracle stored procedure

    I have such a problem: I have to pass array to stored procedure, so I declare type:
    create type tNumberArray as table of number
    and create procedure:
    create or replace procedure proc_1 (in_param in tNumberArray) as
    .... BODY OF PROCEDURE ...
    when I call this procedure from C# like this:
    int []pParam = new int[3] {1,2,3};
    OracleCommand cmd = new OracleCommand("proc_1", dbConn);
    cmd.CommandType = CommandType.StoredProcedure;
    OracleParameter param14 = new OracleParameter("param", OracleDbType.Decimal);
    param14.Value = pParam;
    param14.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    param14.Size = 3;
    param14.Direction = ParameterDirection.Input;
    cmd.Parameters.Add(param14);
    cmd.ExecuteNonQuery();
    an error occures. It say that there invalid number or type of parameters.
    But when I declare both type and procedure in a package everything goes fine.
    What is the matter? Did anybody have the same problem?

    Not I got next problem:
    when I cannot pass parameter to stored procedure and get array fro it. In other words returning array from procedure and passing some input parameters to it does not word!
    Does anybody know why it happens?

  • Passing arrays to procedure

    How can i pass arrays in a procedure as IN parameter
    for eg.
    If I have a procedure which takes an input login id and a input status
         procedure test(loginId IN varchar, status IN varchar)
         -- the procedure does insert and update using the input login id and input status
    Now, suppose i have a bunch of input login ids and a bunch of status, how can i pass the login id and status values as an array to the procedure instead of calling the procedure in a loop?

    This is best done using an object type and collection type, so you can make use of bulk SQL to perform the DML. I've given a short demo below:-
    First your target table...
    SQL> create table my_table ( id number, status varchar2(1) );
    Table created.Now we create an object type ( this defines the record structure for your parameter ). We then create a nested table type (collection) based on this record structure:-
    SQL> create type login_record_ot as object
      2  (  id     number
      3  ,  status varchar2(1)
      4  );
      5  /
    Type created.
    SQL> create type login_records_ntt as table of login_record_ot;
      2  /
    Type created.Now a demo package with a procedure to insert the input collection into the target table. This uses the TABLE expression ( combined with CAST just in case you are on 8i )...
    SQL> create package pkg as
      2     procedure insert_records (
      3               login_records_in in login_records_ntt
      4               );
      5  end pkg;
      6  /
    Package created.
    SQL> create package body pkg as
      2 
      3     procedure insert_records (
      4               login_records_in in login_records_ntt
      5               ) is
      6     begin
      7        insert into my_table ( id, status )
      8        select x.id
      9        ,      x.status
    10        from   table( cast( login_records_in as login_records_ntt )) x;
    11        dbms_output.put_line( sql%rowcount || ' rows inserted.' );
    12     end insert_records;
    13 
    14  end pkg;
    15  /
    Package body created.Now to use it. I'll load a dummy variable with a collection of IDs/statuses and pass them to the pkg.insert_records procedure...
    SQL> declare
      2     some_records login_records_ntt := login_records_ntt(
      3                                          login_record_ot( 1, 'X' ),
      4                                          login_record_ot( 2, 'Y' ),
      5                                          login_record_ot( 3, 'Z' ),
      6                                          login_record_ot( 4, 'A' ),
      7                                          login_record_ot( 5, 'B' )
      8                                          );
      9  begin
    10     pkg.insert_records( some_records );
    11  end;
    12  /
    5 rows inserted.
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from my_table;
            ID S
             1 X
             2 Y
             3 Z
             4 A
             5 BRegards
    Adrian

  • Passing array parameters to Stored procedure

    Hi,
    I need to call a procedure repeatedly with different set of parameters. Instead To do this, I can form a parameter arrays and pass it to the procedure. This is working fine with Oracle 8.1.7 database and Oracle 8.1.7 odbc driver.
    Is there any difference in the way 8.1.6 Oracle ODBC driver behave? When we use the same code with 8.1.6 ODBC driver (with either 8.1.6 database or 8.1.7 database), and pass an array of n elements to the stored procedure, first elemet in the array is processed correctly and for the remaining n-1 times the same value is getting used (which leades to a unique constraint violation since procedure in this case does an insert). Soem of our clients are on 8.1.6 and so we need to get this working on it too.
    Also are you aware if Microsoft ODBC driver implements this correctly. When we traced with ODBC trace, it was executing the procedure n times one after the other thereby simulating the effect but poor performance. (MDAC 2.6).
    Is there any extra settings to be done?
    Thanks
    Sree

    Hi Justin,
    When I installed 8.1.6.6 ODBC driver this problem went off, but I recieved another problem.
    I am getting
    "ORA-01460 unimplemented or unreasonable conversion requested"
    on execution of some procedures with parameter arrays. They work fine with 8.1.7.0.
    Any idea? Is it suggested that I use 8.1.7 ODBC driver with 8.1.6 server/client? Will it create some other problem?
    Thanks
    Sree

  • How can i pass second text  value to the procedure.

    Hi ,
    I have used APEX_ITEM.TEXT(1,null) Item_name,APEX_ITEM.TEXT(2,null) file_name in a sql query and i should pass these two text value as a input parameter to the Procedure.
    So in Process i have written code like
    FOR i IN 1 .. APEX_Application.g_f01.COUNT
    LOOP
    generate_report_data(APEX_Application.g_f01(i)
    ,APEX_Application.g_f02(i)
    END LOOP;
    COMMIT;
    if i enter values in two text columns then two values are passing to a procedure it's fine.
    Here the issue is if i leave the first value as balnk and enter the 2 nd value like Xyz then click on a submit button
    so 2 nd value also passing null to the procedure..
    please anybody guide on this issue..
    Thanks in advance..
    Regards
    Narender B

    Hello Narender,
    >
    Here the issue is if i leave the first value as balnk and enter the 2 nd value like Xyz then click on a submit button
    so 2 nd value also passing null to the procedure..
    >
    This is happening because of FOR i IN 1 .. APEX_Application.g_f01.COUNT in your procedure:
    >
    FOR i IN 1 .. APEX_Application.g_f01.COUNT
    LOOP
    generate_report_data(APEX_Application.g_f01(i)
    ,APEX_Application.g_f02(i)
    END LOOP;
    COMMIT;
    >
    FOR i IN 1 .. APEX_Application.g_f01.COUNT this loop will take only those values of apex_application.g_f01 into consideration whose value is not null.
    Hope it helps!
    Regards,
    Kiran

  • ARRAYS in stored procedures?

    is it possible to have an ARRAY be passed as an In and/or Out
    Parameter in a stored procedure call? if so then can someone
    please show me how? (ie what do i register as the Out, etc.) or
    do i have to use a resultset to access it?
    null

    Artie (guest) wrote:
    : is it possible to have an ARRAY be passed as an In and/or Out
    : Parameter in a stored procedure call? if so then can someone
    : please show me how? (ie what do i register as the Out, etc.)
    or
    : do i have to use a resultset to access it?
    Yes u can pass array to a procedure.
    I have created a package that stores the array
    definition, and the procedure by name abc which takes an array as
    out parameter (script proc1.sql)
    and the second script proc2.sql calls the procedure abc and
    prints some result
    /*File proc1.sql*/
    /*IT creates the package T with the definition of array
    and passes to the procedure*/
    CREATE OR REPLACE PACKAGE T as
    TYPE arr_type is table of number index by binary_integer;
    test_array arr_type;
    END;
    CREATE OR REPLACE PROCEDURE abc(t OUT T.arr_type ) IS
    begin
    for i in 1..10
    loop
    t(i) := i ;
    end loop;
    end abc;
    /*End of Program proc1.sql*/
    /*Program proc2.sql*/
    /*This file calls the procedure abc and prints the result*/
    declare
    test_array T.arr_type;
    begin
    abc(test_array);
    for i in 1..10 loop
    dbms_output.put_line('Result '

  • Passing array to call library function running on VxWorks (cRIO)

    Hello,
    I am using a cRIO 9012 running VxWorks.
    I have a Call library function VI in my application and I want to pass arrays of doubles to this function.
    The problem is that I can not access the values in the array.
    Here is the source code of my function:
    #include "D:\\Programme\\National Instruments\\LabVIEW 8.5\\cintools\\extcode.h"
    double avg_num(double *in1, double *out1)
        double ret;
        ret = in1[0] + out1[0];
        return ret;
    The value of in1[0] and out1[0] is always.
    When passing no arrays but single values, all is fine. But since my application is more complex than this example, I need to pass arrays.
    The block diagram and parameter specification is as shown in the attached screenshots.
    I am compiling the source code with the Gcc 6.3 which is available here:
    http://zone.ni.com/devzone/cda/tut/p/id/5694
    What am I doing wrong?
    Or is passing arrays not supported on cRIO?
    Maybe the makefile needs to be modified?
    Thank you.
    Best regards,
    Christian
    Attachments:
    vi.JPG ‏88 KB
    parameter.JPG ‏41 KB

    I guess I have solved the problem.
    The key was to set the parameter "Minimum size" for all function parameters to <None>.
    Having this, I can read the passed arrays. I do not know why this works but at the moment, it is ok for me.
    Thank you all.

  • Passing variables to a procedure inside a database trigger

    Hi,   I am new to oracle Forms . I am having a table in database . For that table i had written a database trigger which will fire after insert or update . I am using a procedure inside the Trigger . I want to pass arguments to the procedure which is being called in the trigger . The variables which i want to pass to the procedure are one is a primary key and the other is a normal cloumn which are in the same table for which the trigger is written. Can anybody help me regarding this.?

    > But when i m calling it with forms i m getting an error
    You cannot call a database trigger from forms. A trigger is part of the table, e.g.:
    create trigger my_trigger
    before insert or update or delete on my_table
    for each row

Maybe you are looking for