Passing pl/sql array to function

Hi,
I have a function which takes an array:
create or replace
FUNCTION execute_tests(
leg_keys IN type_leg_key_array)
RETURN BOOLEAN
IS
BEGIN
leg_key_array is this:
create or replace
TYPE type_leg_key_array AS TABLE OF NUMBER(6, 3);
I would like to test this funtion by passing it some array:
DECLARE
LEG_KEYS DEV_SWA30PRE.TYPE_LEG_KEY_ARRAY;
V_RETURN BOOLEAN;
BEGIN
-- LEG_KEYS := NULL;
v_Return := EXECUTE_TESTS(LEG_KEYS);
END;
What is wrong with the snippet above?
Thanks

Hi,
user610868 wrote:
Hi,
I have a function which takes an array:
create or replace
FUNCTION execute_tests(
leg_keys IN type_leg_key_array)
RETURN BOOLEAN
IS
BEGIN
leg_key_array is this:
create or replace
TYPE type_leg_key_array AS TABLE OF NUMBER(6, 3);
I would like to test this funtion by passing it some array:
DECLARE
LEG_KEYS DEV_SWA30PRE.TYPE_LEG_KEY_ARRAY;
V_RETURN BOOLEAN;
BEGIN
-- LEG_KEYS := NULL;
v_Return := EXECUTE_TESTS(LEG_KEYS);
END;
What is wrong with the snippet above?Why do you think anything is wrong? Are you getting an error message? Post the complete error message, including line numbers. Does the error occur when you create the type, when you create the function, when you call the function, or someplace else?
The only errors I see are probably due to how you chose to post it. For example, there is no RETURN or END statement in execute_tests.
Did you create the type before trying to use it in the function?
What is DEV_SWA30PRE? Is that a schema? Does that schema also contain the fucntion? Is that who is running the anonymous block? If there are other schemas involved, what are they? What are they doing? What privileges do they have on the type or the function?
Post a complete test script that people can run to re-create the problem and test their ideas.

Similar Messages

  • Problem passing oracle.sql.ARRAY to Oracle

    I am having ClassCastException when I try to pass a oracle.sql.ARRAY to a Oracle Package.
    Here is my code:
    PreparedStatement stmt = null;
    String strArray[] = { "1,2,3,4,5" };
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    //encounter Exception on the line below.
    ARRAY array_to_pass = new ARRAY( descriptor, dbConnection, strArray );
    String queryStr = "begin TEST_PAC_1.TEST_PROC_2(?); end;";
    stmt = dbConnection.prepareStatement(queryStr);
    stmt.setArray( 1, array_to_pass );
    stmt.execute();
    I understand that oracle.sql.ARRAY has been replaced by weblogic.jdbc.vendor.oracle.OracleArray in Weblogic.
    MY QUESTION IS: HOW DO I INSERT MY STRING ARRAY INTO THE OracleArray and pass it to the plsql.
    Really frustrated searching through the forums for the whole day,
    Thanks,

    Try this if you are at weblogic 8.1:
    Connection con = getConnectionFromDataSource();
    Connection vendorConnection = ((WLConnection)con).getVendorConnection();
    // use direct oracle connection.
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    vendorConnection.close();
    Beware that you should be very careful as you are going to use a direct vendor
    connection.
    The better aproach is to pass the string array as a delimited string to your storad
    procedure and parse it in the SP - then you don't have to mess up with vendor-specific
    handling.
    Hope this helps.
    Regards,
    Slava Imeshev
    "Daddy Daddy" <[email protected]> wrote in message news:24349835.1097143668312.JavaMail.root@jserv5...
    I am having ClassCastException when I try to pass a oracle.sql.ARRAY to a Oracle Package.
    Here is my code:
    PreparedStatement stmt = null;
    String strArray[] = { "1,2,3,4,5" };
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "TEST_PAC_1.TEST_COLL_2", dbConnection );
    //encounter Exception on the line below.
    ARRAY array_to_pass = new ARRAY( descriptor, dbConnection, strArray );
    String queryStr = "begin TEST_PAC_1.TEST_PROC_2(?); end;";
    stmt = dbConnection.prepareStatement(queryStr);
    stmt.setArray( 1, array_to_pass );
    stmt.execute();
    I understand that oracle.sql.ARRAY has been replaced by weblogic.jdbc.vendor.oracle.OracleArray in Weblogic.
    MY QUESTION IS: HOW DO I INSERT MY STRING ARRAY INTO THE OracleArray and pass it to the plsql.
    Really frustrated searching through the forums for the whole day,
    Thanks,

  • Pass PL/SQL collection as function parameter over DBLink

    Hi all,
    I am trying to do the following;
    ---Remote database
    --create SQL type
    create type attributeidarray as table of varchar2(255);
    --create a package specs
    CREATE OR REPLACE PACKAGE testp
    AS
    TYPE ref_res IS REF CURSOR;
    FUNCTION foo (i NUMBER)
    RETURN NUMBER;
    FUNCTION foo1 (i NUMBER, j attributeidarray)
    RETURN NUMBER;
    END;
    --create package body
    CREATE OR REPLACE PACKAGE BODY testp
    IS
    --Function does nothing other than return number
    FUNCTION foo (i NUMBER)
    RETURN NUMBER
    IS
    res ref_res;
    a array_n;
    BEGIN
    OPEN res
    FOR
    SELECT *
    FROM DUAL;
    RETURN 1;
    END;
    --Function takes the collection as imput and does nothing with it. Function just returns number
    FUNCTION foo1 (i NUMBER, j attributeidarray)
    RETURN NUMBER
    IS
    res ref_res;
    a array_n;
    BEGIN
    OPEN res
    FOR
    SELECT *
    FROM DUAL;
    RETURN 1;
    END;
    END;
    --"Near" Database ..
    --create a SQL type
    --This is the exactly the same as in remote database
    create type attributeidarray as table of varchar2(255);
    --create a DBLink
    create database link con_to_remote_db
    connect to remotedbuser
    identified by "swordfish"
    using 'remotedb'
    --call the remote functions and pass a collection object
    SQL> DECLARE
    2 a attributeidarray;
    3 BEGIN
    4 SELECT CAST (attributeidarray (1, 2) AS attributeidarray)
    5 INTO a
    6 FROM DUAL;
    7
    8 :b := testp.foo@con_to_remote_db (2);
    9 END;
    10 /
    PL/SQL procedure successfully completed.
    SQL> print b
    B
    1
    SQL>
    --so far so good...
    SQL> DECLARE
    2 a attributeidarray;
    3 BEGIN
    4 SELECT CAST (attributeidarray (1, 2) AS attributeidarray)
    5 INTO a
    6 FROM DUAL;
    7
    8 :b := testp.foo1@con_to_remote_db (2, a);
    9 END;
    10 /
    :b := testp.foo1@con_to_remote_db (2, a);
    ERROR at line 8:
    ORA-06550: line 8, column 10:
    PLS-00306: wrong number or types of arguments in call to 'FOO1'
    ORA-06550: line 8, column 4:
    PL/SQL: Statement ignored
    --Oops...doesn't seem to recognize the collection type :( /b]
    So I wish to know the following;
    - Even though the definition for type is the same, why is the remote DB not recognizing my type?
    - It would be helpful if any one can let me know the correct method to pass a collection type with a example.
    I would appreciate any help in resolving this issue.
    Thanks,
    prashant

    Not possible. For valid technical reasons.
    Definitions are local to a database. You can define a SQL user type called TMyType in your database. I can define one in mine with the same name.
    Can you now call my database, passing a collection of your TMyType to me? How do we (or Oracle) know that your definition and my definition is the same? Or if they were the same when you compiled your code (and your Oracle checked my Oracle to confirm), that they still are the same and that I did not in the meantime altered the type? Or even dropped it?
    For types/collections to be transparently passed across to database links, we need something along the lines of:
    a) global types
    b) runtime checking of types
    Both are problematic to implement and maintain. With (a) there is the issue of dependencies. The global type cannot be changed before all dependencies on all subscribers have been resolved. With (b) there is the issue of performance, checking the type definitions with every single call on the local & remote instances to compare.
    It would be a nice feature to have... but it would fail to live up to expectation if not implemented in a robust and performant way.
    Alternative. "Insert" data via a remote proc into a remote collection. This allows you to push data into a PGA memory structure on the remote side and when done, allows you to tell that remote proc to "flush" (forall insert/update/delete) the contents of that structure to disk.

  • Passing collection or array to function: shallow copy or not?

    Hello all,
    When passing a collection or an array to a function, what is most used practice to store the given collection in some class member field: reference-copy or a shallow copy?
    I believe it's frustrating to see that there is no real 'standard' about this: some developers copy the whole collection/array, others prefer to simply copy the reference. I tend to agree with the latter group:
    - it's the user's responsibility if he wants the class to use a copied version instead of the 'original' version of the collection/array.
    - most of the times, a copy is not needed, and therefor a shallow copy is pure waste of resources.
    - when nothing is known about the given collection, and there are also no restrictions on the collection to be given, it could be everything: ArrayList? HashSet? SortedSet? AnUnknownImplementation?
    reference copy:
    class ComeClass
        private ArrayList list;
        public SomeClass(ArrayList list) { this.list = list; }
    }shallow copy:
    class ComeClass
        private List list;
        public SomeClass(List list) { this.list = new ArrayList(list); }
    }What are your thoughts about this?

    basically, it's how much access you want to provides.
    public SomeClass(ArrayList list) { this.list = list; }to me, if some other class has a reference to the list object and start modifying it..Someclass internal data (the list) is also modified...thus breaking encapsulation.
    yes, in multithread enviroment, sharing the list(by reference can lead to some hard bug to debug), so it;s much safer to copy (clone) the list. Java does this and provides you the MultiCaster class to make thing easier for you.
    even with synchronization, there are issues you have to look at (such as deadlock)..you can synchronize the list, but can still run into a dead lock
    list is synchronized in class A
    class B have object (that's in list and call the list (wait due to class A synchronization)
    list tries to invoke method of class B, but wait (class B is lock)..thus..deadlock.
    it's a crued exapmle..but i think you get the point.
    the saying is that to make a safer application..declare all you object immutable or restrict access to your private data. Of course, performance wise, we have to comprise sometime.
    example..a list with over 500,000 objects..you might not want to to clone the reference.

  • Pass SQL into a Function

    Is it possible to pass a SQL into a Function
    DECLARE
       f        sys_refcursor;
       RESULT   NUMBER;
       FUNCTION myfunction (r sys_refcursor)
          RETURN NUMBER
       IS
       BEGIN
          RETURN TO_NUMBER (TO_CHAR (r.dt, 'DD'));
       END;
    BEGIN
       OPEN f FOR
          SELECT SYSDATE dt
            FROM DUAL;
       RESULT := myfunction (f);
       CLOSE f;
    END;

    Yes you are allowed to pass ref cursor but they have to processed the way you processur cursor i.e. OPEN, FETCH, CLOSE.
    See demonostration of working code:
    SQL>DECLARE
      2     f        sys_refcursor;
      3     RESULT   NUMBER;
      4
      5     FUNCTION myfunction (r sys_refcursor)
      6        RETURN NUMBER
      7     IS
      8     v_currDate DATE;
      9
    10     BEGIN
    11        IF r%ISOPEN THEN
    12          FETCH r INTO v_currDate;
    13        END IF;
    14
    15        RETURN TO_NUMBER (TO_CHAR (v_currDate, 'DD'));
    16     END;
    17  BEGIN
    18     OPEN f FOR
    19        SELECT SYSDATE dt
    20          FROM DUAL;
    21
    22     RESULT := myfunction (f);
    23
    24     DBMS_OUTPUT.PUT_LINE('Date : ' || RESULT );
    25
    26     CLOSE f;
    27  END;
    28  /
    Date : 23
    PL/SQL procedure successfully completed.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Passing a Variant array to ArrayToImage Function

    Hi,
    I need help passing a Variant array to the ArrayToImage function in the NI Vision library.
    I have no problems using the ImageToArray function - but when going back to the CWIMAQImage type the application throws an exception.
    Are there any code samples for doing this?
    Thanks!

    Hello,
    Thank you for posting to the NI forums! Try calling the ImageToArray function then immediately passing the resultant array back to ArrayToImage. That will determine whether the ArrayToImage function is causing the error, or the array that is passed into it. Can you post a small sample of how you call the ArrayToImage function and the errors that are thrown?
    Thanks,
    Maclean G.
    Applications Engineering
    National Instruments

  • Passing 3d arrays to functions in C

    So.. I have a certain char array[8][3][30], declared as ***array, and allocated as the program progresses. I'd like to pass that to an external function, but GCC pukes out warnings that the type case isn't right, and anytime I access it in the function, it segfaults (basically, it doesn't pass properly).
    my function prototype:
    int parse_table(char ***table);
    and code to pass it:
    parse_table(table);
    anyone knowledgable on this?

    tardo wrote:main()
    char ***table;
    parse_table(table);
    use_table(table);
    parse_table(char ***table)
    // read one value from file
    // determine other two values from file input
    // allocate memory depending on values (varies with file input)
    use_table(char ***table)
    // programming homework (probably a tree)
    AHEM, so, I actually bothered to read this properly this time . If this is actually how you have your code structured, this is definitely a problem. Think about this: "table" is of type "char ***", correct? parse_table takes a type "char ***"... you have pass-by-value semantics here. So, essentially, parse_table will receive a COPY of an unitialized memory location. You will then set this local copy to the return of malloc (e.g. something lik table = malloc(/*stuff*/)). However, this is not affecting the table seen in main()! Essentially, you should have something like:
    int main() {
    char ***table = parse_table();
    /* rest of main */
    char *** parse_table() {
    /* Stuff that mallocs into local_table pointer */
    return local_table;
    Where, you malloc the stuff in parse_table, and return that pointer. Alternatively (and painfully), you could do something weird like:
    int main() {
    char ***table;
    parse_table(&table);
    /* rest of main */
    void parse_table(char ****table) { /* Note: four "asterisks", not three! */
    /* malloc evilness in here, with something like (*table) = malloc(/* stuff */) */
    (Don't do this, it's ugly and unnecessary)
    Just to be completely pendantic, check it this sample code I whipped up:
    #include <stdlib>
    #include <stdio>
    void evil_and_wrong(char *f) {
    printf("Memory location we'd allocate to (evil_and_wrong): %un", &f);
    f = (char*)malloc(5*sizeof(char));
    f[0]='p';
    void my_alloc_f(char **f) {
    printf("Memory location we'd allocate to (my_alloc_f): %un", f);
    (*f) = (char*)malloc(5*sizeof(char));
    (*f)[0]='p';
    char * nicer_my_alloc_f() {
    char *local_f = (char*) malloc(5*sizeof(char));
    local_f[0]='p';
    return local_f;
    int main() {
    char *f;
    printf("ACTUAL Memory location: %un", &f);
    evil_and_wrong(f);
    // We won't try anything with "f" here, since it'll segault...
    my_alloc_f(&f);
    printf("Should see: %un", 'p');
    printf("See: %un", f[0]);
    free(f);
    f = nicer_my_alloc_f();
    printf("See: %un", f[0]);
    free(f);
    return 0;
    Look at the outputted memory locations, and think about the fact you're trying to store the address of the allocated memory...

  • PL/SQL array passed to SQL IN

    Hi,
    I have a PL/SQL array which type is defined like this:
    create or replace type type_id_array as table of number(6, 3);
    then i create a variable and initilaize:
    var_1 type_id_array;
    var_1 := .....
    then i have a select statement.
    select * from table t where t.id in(var_1)
    That's it, i want to use the array in an SQL in. This seems not possible.
    Can you explain why? Any alternate solutions?
    Thanks

    user610868 wrote:
    That's it, i want to use the array in an SQL in. This seems not possible.
    Can you explain why? Any alternate solutions?SQL supports set commands specifically for arrays (in addition to the using the TABLE() method mentioned). For example:
    SQL> create or replace type TNumbers is table of number;
      2  /
    Type created.
    SQL>
    SQL> declare
      2          numList TNumbers;
      3          cnt     integer;
      4  begin
      5          numList := new TNumbers(1,2,3,4,5,6,7);
      6          select
      7                  count(*) into cnt
      8          from    user_objects
      9          where   TNumbers(object_id) member of numList;
    10          DBMS_OUTPUT.put_line( 'cnt='||cnt );
    11  end;
    12  /
    cnt=0
    PL/SQL procedure successfully completed.Obviously there are performance considerations when using arrays/collections in SQL. So before choosing a method, evaluate the performance.

  • ABAP/4 Open SQL array insert results in duplicate database records in SM58

    Hi Everyone,
    I am testing a file to idoc scenario in my Quality system. When I passed the input file, the mapping executed successfully and there are no entries in SMQ2 but still the idoc wasn't created in the ECC system. When I have checked in TRFC, I am getting the error  ABAP/4 Open SQL array insert results in duplicate database records for IDOC_INBOUND_AYNCHRONOUS function module. I thought this is a data issue and I have tested with a fresh data which was never used for testing in Quality but even then I am getting the same error.Kindly advise.
    Thanks,
    Laawanya

    use FM idoc_status_write_to_database to change the IDoc status from 03 to 30 and then  run WE14 or  RSEOUT00 to change the status back to 03
    resending idoc from status 03 ...is a data duplicatino issue on receiving side...why do u need to do that ?
    Use WE19 tcode to debug
    In we19
    1)U can choose your Idoc number in existing Idoc textbox
    2)Press execute
    3)u will display ur Idoc struct
    4)Dbl click on any field then u can modify its content
    5)PressStd Outbound Processing Btn to process modified Idoc
    Thats it

  • How to find out the execution time of a sql inside a function

    Hi All,
    I am writing one function. There is only one IN parameter. In that parameter, i will pass one SQL select statement. And I want the function to return the exact execution time of that SQL statement.
    CREATE OR REPLACE FUNCTION function_name (p_sql IN VARCHAR2)
    RETURN NUMBER
    IS
    exec_time NUMBER;
    BEGIN
    --Calculate the execution time for the incoming sql statement.
    RETURN exec_time;
    END function_name;
    /

    Please note that wrapping query in a "SELECT COUNT(*) FROM (<query>)" doesn't necessarily reflect the execution time of the stand-alone query because the optimizer is smart and might choose a completely different execution plan for that query.
    A simple test case shows the potential difference of work performed by the database:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    Session altered.
    SQL>
    SQL> drop table count_test purge;
    Table dropped.
    Elapsed: 00:00:00.17
    SQL>
    SQL> create table count_test as select * from all_objects;
    Table created.
    Elapsed: 00:00:02.56
    SQL>
    SQL> alter table count_test add constraint pk_count_test primary key (object_id)
    Table altered.
    Elapsed: 00:00:00.04
    SQL>
    SQL> exec dbms_stats.gather_table_stats(ownname=>null, tabname=>'COUNT_TEST')
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.29
    SQL>
    SQL> set autotrace traceonly
    SQL>
    SQL> select * from count_test;
    5326 rows selected.
    Elapsed: 00:00:00.10
    Execution Plan
    Plan hash value: 3690877688
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |            |  5326 |   431K|    23   (5)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| COUNT_TEST |  5326 |   431K|    23   (5)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
            419  consistent gets
              0  physical reads
              0  redo size
         242637  bytes sent via SQL*Net to client
           4285  bytes received via SQL*Net from client
            357  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
           5326  rows processed
    SQL>
    SQL> select count(*) from (select * from count_test);
    Elapsed: 00:00:00.00
    Execution Plan
    Plan hash value: 572193338
    | Id  | Operation             | Name          | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT      |               |     1 |     5   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE       |               |     1 |            |          |
    |   2 |   INDEX FAST FULL SCAN| PK_COUNT_TEST |  5326 |     5   (0)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
             16  consistent gets
              0  physical reads
              0  redo size
            412  bytes sent via SQL*Net to client
            380  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL>As you can see the number of blocks processed (consistent gets) is quite different. You need to actually fetch all records, e.g. using a PL/SQL block on the server to find out how long it takes to process the query, but that's not that easy if you want to have an arbitrary query string as input.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle:
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Call a PL/SQL procedure or function from applet

    Could anyone please let me know how I could call a PL/SQL procedure
    or function from a JDBC method from applet with Internet Explorer?

    It depends from where you are calling your PLSQL routine. If it is SQL*Plus then you can use & (ampersand) with the variable to be input at run time.
    If you are executing the PLSQL routine from another application (some front end application) then it's not possible. Because when a procedure is executing at server side, the front end application does not have control, and the control is only transfered back to front end application when the PLSQL routine either completes successfully or throws an exception.
    In either case, you can not go back to the PLSQL routine.
    In this case, what you can do is, write code in your front end application to get that variable value from user and then pass that value to PLSQL routine.

  • Can't we pass java.sql.Connection as parameter toDatum() method

    I am in mid of java 1.3 to 1.4 migration, now I am getting the below error.can't we pass java.sql.Connection as a param to toDatum(), but I did the same before for another module and it worked fine, now I am getting the error.
    any changes need to be done?
    [b]toDatum(oracle.jdbc.driver.OracleConnection,java.lang.String) in oracle.jpub.runtime.MutableArray cannot be applied to (java.sql.Connection,java.lang.String)
    return array.toDatum(c, SQL_NAME);
    ^
    1 error
    I changed to use
    import oracle.sql.ORAData;
    import oracle.sql.ORADataFactory;
    instead of
    import oracle.sql.CustomDatum;
    import oracle.sql.CustomDatumFactory;

    In general, it's bad practice to be that "open" with regards to parameters to methods, especially when using remote invocations. However, if you really, really, really, really need to - and I doubt you do - you can use Serializable for the type of parameter. But that's still inelegant and, well, raises all sorts of issues, starting with your design...

  • How to create oracle.sql.array

    I need to create an oracle.sql.array to pass in my custom objects array to the database. I know you can create it using the ArrayDescriptor class but the problem with that is the connection object is need.
    I am using the writeSql() method of the SQLData interface. I therefore dont have the connection object. Any ideas?

    haha
    you misunderstand. i have in my code:
    <code>
         // update the organisation
         public boolean setOrganisation(Organisation pOrg) {
              Organisation org = pOrg;
              OracleCallableStatement callStat = null;
              Connection conn = null;
              boolean OK = false;
              try {
                   conn = getConnection(getUserName());
                   pOrg.setConnection(conn);
                   callStat = (OracleCallableStatement) conn.prepareCall("{call p_cmt.update_organisation(?)}");
                   callStat.setObject(1, org);
                   callStat.execute();
                   OK = true;
              } catch (Exception e) {
                   logger.severe("error writing organisation with id " + org.getId() + ". " + e);
              } finally {
                   cleanUpConnections(conn, callStat);
              return OK;
    </code>
    This writes the object organisation to the database. Now in the class organisation i have the following method which is called automatically when writing the organisation object to the database:
    <code>
         public void writeSQL(SQLOutput p_stream) throws SQLException {
              p_stream.writeInt(id);
              p_stream.writeObject(country);
         if (finIndexArr == null)
              finIndexArr = new ListElement[0];
         ArrayDescriptor af = ArrayDescriptor.createDescriptor(
         ObjectMapper.elementList, conn);
         ARRAY arr = new ARRAY(af, conn, finIndexArr);          
              p_stream.writeArray(arr);
    </code>
    The problem is the last bit. To put the finIndexArr into an array i need the connection object. So i have to pass into the organisation object the connection object which seems unneccessary and pointless to me. I was just looking at an alternative way of creating the array without the need of the connection object. Since the setOrganisation() above has the connection to the database i dont see why i need to specify it in the array as well

  • Bind PL/SQL array to PHP array

    Hi all!
    I try to bind a PL/SQL array (nested tables, index by integer) returned by a PL/SQL-function to an PHP array.
    Here is the code:
    create or replace package MyPackage as
    TYPE my_type IS TABLE OF VARCHAR2(1024);
    FUNCTION MyFunction RETURN my_type;
    end MyPackage;
    create or replace PACKAGE BODY MyPackage is
    FUNCTION MyFunction RETURN my_type IS
    t_docs my_type;
    begin
    t_docs := my_type('val0','val1','val2');
    return t_docs;
    end MyFunction;
    end MyPackage;
    In the PHP-code ist looks like this
    $query = "begin :vals := MyPackage.MyFunction; end;";
    $stmt = oci_parse ($conn, $query);
    oci_bind_array_by_name($stmt, ":vals", $vals_array, 5, 512, SQLT_CHR);
    oci_execute ($stmt);
    Output:
    PLS-00382: expression is of wrong type. Error in Line....
    This error point to
    begin :vals := MyPackage.MyFunction; end;
    ^^^
    Questions:
    Is it generally possible to bind a pl/sql array to a php array? Or only the other was around?
    Could you please post a snipet of code how to do it the right way :-)
    Thanks a lot for your help! Christian

    As you noted, you can't return a PL/SQL array and map it to a PHP array when it is a record type. Likewise, you can't map an object type to a PHP array. You can return a reference cursor through PL/SQL, and then fetch the function result with oci_fetch_assoc($rc).
    Alternatively, you can return an object type collection or a pipelined table function result into PHP. It's a bit long but you'll find examples on my blog. Start here, and there's a link to a full discussion of pipelined table functions:
    http://blog.mclaughlinsoftware.com/2009/03/19/beats-a-reference-cursor/
    This is an object table example, which you may prefer over pipelined table functions:
    http://blog.mclaughlinsoftware.com/2009/03/23/object-record-collections/
    Hope this helps.

  • SQL User Defined Functions for performing statistical calculations

    Hi!
       I hope you can help.  I just wasn’t sure where to go with this question, so I’m hoping you can at least point me in the right direction.
       I’m writing a SQL Server stored procedure that returns information for a facility-wide scorecard-type report.  The row and columns are going to be displayed in a SQL Server Reporting Services report. 
       Each row of information contains “Current Month” and “Previous Month” numbers and a variance column.  Some rows may compare percentages, others whole numbers, others ratios, depending on the metric they’re measuring.  For each row/metric the company has specified whether they want to see a t-test or a chi-squared statistical test to determine whether or not there was a statistically significant difference between the current month and the previous month. 
       My question is this:  Do you know where I can find a set of already-written user defined functions to perform statistical calculations beyond the basic ones provided in SQL Server 2005?  I’m not using Analysis Services, so what I’m looking for are real SQL User Defined Functions where I can just pass my data to the function and have it return the result within a stored procedure. 
       I’m aware that there may be some third-party statistical packages out there we could purchase, but that’s not what I’m looking for.   And I’m not able to do anything like call Excel’s analysis pack functions from within my stored procedure.   I’ve asked.   They won’t let me do that.   I just need to perform the calculation within the stored procedure and return the result.
       Any suggestions?  Is there a site where people are posting their SQL Server UDF’s to perform statistical functions?  Or are you perhaps aware of something like a free add-in for SQL that will add statistical functions to those available in SQL?   I just don’t want to have to write my own t-test function or my own chi-squared function if someone has already done it.
     Thanks for your help in advance!  Oh, and please let me know if this should have been posted in the TSQL forum instead.  I wasn't entirely sure.
    Karen Grube

    STATS_T_TEST_
    docs.oracle.com/cd/B19306_01/server.102/b14200/functions157.htm 
    STATS_T_TEST_ONE: A one-sample t-test
    STATS_T_TEST_PAIRED: A two-sample, paired t-test (also known as a crossed t-test)
    STATS_T_TEST_INDEP: A t-test of two independent groups with the same variance (pooled variances)
    STATS_T_TEST_INDEPU: A t-test of two independent groups with unequal variance (unpooled variances)

Maybe you are looking for