Parameters

Return Values

Returns a new LOB or FILE descriptor on success, FALSE on error.

Examples

Example #1 oci_new_descriptor() example

<?php/* This script is designed to be called from a HTML form. * It expects $user, $password, $table, $where, and $commitsize * to be passed in from the form. The script then deletes * the selected rows using the ROWID and commits after each * set of $commitsize rows. (Use with care, there is no rollback) */$conn = oci_connect($user, $password);$stmt = oci_parse($conn, "select rowid from $table$where");$rowid = oci_new_descriptor($conn, OCI_D_ROWID);oci_define_by_name($stmt, "ROWID", $rowid);oci_execute($stmt);while (oci_fetch($stmt)) {$nrows = oci_num_rows($stmt);$delete = oci_parse($conn, "delete from $table where ROWID = :rid");oci_bind_by_name($delete, ":rid", $rowid, -1, OCI_B_ROWID);oci_execute($delete); echo "$nrows\n"; if (($nrows % $commitsize) == 0) {oci_commit($conn); }}$nrows = oci_num_rows($stmt);echo "$nrows deleted...\n";oci_free_statement($stmt);oci_close($conn);?>

Notes

Note:

In PHP versions before 5.0.0 you must use ocinewdescriptor() instead.
This name still can be used, it was left as alias of
oci_new_descriptor() for downwards compatability.
This, however, is deprecated and not recommended.

See Also

User Contributed Notes 14 notes

Here is an example of retrieving a CLOB as an output parameter from a stored procedure. This is a bit hack-y and maybe there's a cleaner way to do this, but I couldn't find one. The following definitely works with Oracle 9:

// the query to call the procedure, which includes declaring the
// output parameter and assigning the result to a variable to be bound.
$qry = '
declare clob_out clob;
begin
myprocedure(someparam_in, clob_out);
:myclob := clob_out;
end;
';

I had the same problem with updating the lobs with shorter content as in one of the notes above. The addition of "\0" at the end of the replacement text didn't help either. But the following worked perfectly:

I found another method of inserting/updating lob data. It works the same was as passing lob parameters to a stored procedure and avoids the need for a RETURNING clause.
$lob = OCINewDescriptor($conn, OCI_D_LOB);
$stmt = OCIParse($conn,"insert into $table (id, the_blob)
values(my_seq.NEXTVAL, :the_blob)");
OCIBindByName($stmt, ':the_blob', &$lob, -1, OCI_B_BLOB);
$lob->WriteTemporary($data);
OCIExecute($stmt, OCI_DEFAULT);
$lob->close();
$lob->free();
OCICommit($conn);

There are some cases involving triggers where you can't use a RETURNING clause, so this method can come in handy. The case where I needed it was updating a view that had an instead-of update trigger.

This doesn't work for me in PHP4. I believe it is because the
implementation of OCIWriteTemporaryLob() always binds as a CLOB.
(This is true as of php4-STABLE-200403170230). In PHP5 the interface
has changed and a type parameter is permitted.

Two examples of retrieving CLOBs from the database. They are almost identical. The first is using a package(and cursor) which is how I interface to Oracle at work, and the second is using straight SQL, which most people post examples in.

I also convert the case from upper to lower, since that is how I prefer to work with assoc arrays...

Instead of using the get_class() function you could use the OCIColumnType() function which (in this case) would return 'CLOB' as a result...

Just a note. When INSERTing a CLOB, if a VALUES clause is used, Oracle notes: You cannot initialize an internal LOB attribute in an object with a value other than empty or null. That is, you cannot use a literal.

That's why all the examples here INSERT an EMPTY_CLOB(), and use RETURNING to grab the pointer.

However, a CLOB can also be INSERTed via a SELECT statement, and that won't require any descriptors.