'Mapping a collection to PHP variable for an Oracle DEQUEUE_ARRAY procedure

I am trying to map the result of a DBMS_AQ.DEQUEUE_ARRAY function to a PHP variable.

There's a SQL type defined that would hold the result of the function's payload.

CREATE TYPE INTERNAL_TYPE_ARRAY AS TABLE OF INTERNAL_TYPE;

and my script currently looks like the following:

<?php

$connection = OracleBase::getOracleConnection();

$query = <<<PLSQL
    DECLARE
      dequeue_options DBMS_AQ.DEQUEUE_OPTIONS_T;
      msg_prop_array  DBMS_AQ.MESSAGE_PROPERTIES_ARRAY_T;
      msg_id_array    DBMS_AQ.MSGID_ARRAY_T;
      dequeued_cnt    PLS_INTEGER;
      l_array_size    PLS_INTEGER := 1;
      payloads        INTERNAL_TYPE_ARRAY;

      BEGIN
        payloads := INTERNAL_TYPE_ARRAY();
        payloads.EXTEND(l_array_size);

        msg_prop_array := DBMS_AQ.MESSAGE_PROPERTIES_ARRAY_T();
        msg_prop_array.EXTEND(l_array_size);

        msg_id_array := DBMS_AQ.MSGID_ARRAY_T();
        dequeue_options.wait := 5;

        dequeued_cnt := DBMS_AQ.DEQUEUE_ARRAY(
            QUEUE_NAME               => 'user.some_queue',
            DEQUEUE_OPTIONS          => dequeue_options,
            ARRAY_SIZE               => l_array_size,
            MESSAGE_PROPERTIES_ARRAY => msg_prop_array,
            PAYLOAD_ARRAY            => payloads,
            MSGID_ARRAY              => msg_id_array
        );

        :COLLECTION := payloads;

        COMMIT;
    END;
PLSQL;

$stmt = oci_parse($connection, $query);
$collection = oci_new_collection($connection, 'INTERNAL_TYPE_ARRAY', 'USER');
oci_bind_by_name($stmt, ':COLLECTION', $collection, 1, SQLT_NTY);
oci_execute($stmt);

$collection->getelem(0); // results in PHP Notice:  OCICollection::getElem(): Unknown or unsupported type of element: 108

Unfortunately, my knowledge of Oracle AQ is quite rudimentary and the documentation for PHP is not that detailed. I'd appreciate any insights on how to get this done. Thanks!

EDIT:

I tried by wrapping it all up into a procedure that returns something as follows:

$sql = <<<SQL
    CREATE or REPLACE PROCEDURE SAMPLE_DEQUEUE(
        ret out INTERNAL_TYPE_ARRAY
    ) as
    dequeue_options DBMS_AQ.DEQUEUE_OPTIONS_T;
    msg_prop_array  DBMS_AQ.MESSAGE_PROPERTIES_ARRAY_T;
    msg_id_array    DBMS_AQ.MSGID_ARRAY_T;
    dequeued_cnt    PLS_INTEGER;
    l_array_size    PLS_INTEGER := 1;
    BEGIN
    msg_prop_array := DBMS_AQ.MESSAGE_PROPERTIES_ARRAY_T();
    msg_prop_array.EXTEND(l_array_size);
    
    msg_id_array := DBMS_AQ.MSGID_ARRAY_T();
    dequeue_options.navigation := DBMS_AQ.FIRST_MESSAGE;
    dequeue_options.wait := 10;
    
    dequeued_cnt := DBMS_AQ.DEQUEUE_ARRAY(
        QUEUE_NAME               => 'user.some_queue',
        DEQUEUE_OPTIONS          => dequeue_options,
        ARRAY_SIZE               => l_array_size,
        MESSAGE_PROPERTIES_ARRAY => msg_prop_array,
        PAYLOAD_ARRAY            => ret,
        MSGID_ARRAY              => msg_id_array
    );
    COMMIT;
    END;
SQL;

I can then do something like this:

$sql = "begin SAMPLE_DEQUEUE(:RET); end;";
$stmt = oci_parse($connection, $sql);
$collection = oci_new_collection($connection, 'INTERNAL_TYPE_ARRAY', 'USER');
oci_bind_by_name($stmt, ':RET', $collection, 1, SQLT_NTY);
$r = oci_execute($stmt);

This still results in:

PHP Notice:  OCICollection::getElem(): Unknown or unsupported type of element: 108


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source