English 中文(简体)
Why is PHP s OCI8/Oracle oci_bind_array_by_name not working for me?
原标题:

I m trying to bind a php variable to pl/sql array. The pl/sql procedure works fine when I execute it manually and set the bind, so I know that s not the problem. It s the oci_bind_array_by_name that is causing problems.

I get the following error message for the line in the PHP code below where I call the oci_bind_array_by_name function:

Warning: oci_bind_array_by_name() [function.oci-bind-array-by-name]: You must provide max length value for empty arrays

I m confused because I am in fact providing a max length (250) in the function call per the documentation:

http://php.net/manual/en/function.oci-bind-array-by-name.php I m using PHP 5.1.6

Here is the relevant PHP code:

$SQL = "BEGIN MYPKG.PROCESS_USERS(:USER_ID_ARRAY); END;";

$conn = self::getConnection();
$stmt = OCIParse($conn, $SQL);
$userIdArray= array(); /*I ve also tried not initializing the OUT array (same error)
If I put some dummy value into the $userIdArray the procedure will run fine, but the results afterward will contain only that dummy value and not the output of the procedure*/
oci_bind_array_by_name($stmt, USER_ID_ARRAY , $userIdArray, 250, -1, SQLT_VCS);

I have an array type defined in the package:

TYPE USER_ID_ARRAY IS TABLE OF VARCHAR2(250) INDEX BY BINARY_INTEGER;

The PROCESS_USERS function in an abbreviated form:
PROCEDURE PROCESS_USERS(p_userIdArray out USER_ID_ARRAY) AS
  --Code here which processes all waiting users and returns their IDs in p_userIdArray
END PROCESS USERS;
最佳回答

And I feel like a fool because I did not read the API closely enough. Apparently I was specifying the max_table_length but the error message was referring to the max_item_length which I left as -1... but that s a no-no since I m binding an OUT parameter instead of an IN one.

Changed the bind like so and it now works:

oci_bind_array_by_name($stmt, USER_ID_ARRAY , $userIdArray, 250, 250, SQLT_VCS);
问题回答

暂无回答




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签