oci_bind_array_by_name
(PHP 5 >= 5.1.2, PHP 7, PECL OCI8 >= 1.2.0)
oci_bind_array_by_name — Binds a PHP array to an Oracle PL/SQL array parameter
Description
$statement
, string $name
, array &$var_array
, int $max_table_length
[, int $max_item_length
= -1
[, int $type
= SQLT_AFC
]] ) : bool
Binds the PHP array var_array
to the Oracle
placeholder name
, which points to an Oracle PL/SQL
array. Whether it will be used for input or output will be determined at
run-time.
Parameters
-
statement
-
A valid OCI statement identifier.
-
name
-
The Oracle placeholder.
-
var_array
-
An array.
-
max_table_length
-
Sets the maximum length both for incoming and result arrays.
-
max_item_length
-
Sets maximum length for array items. If not specified or equals to -1, oci_bind_array_by_name() will find the longest element in the incoming array and will use it as the maximum length.
-
type
-
Should be used to set the type of PL/SQL array items. See list of available types below:
-
SQLT_NUM
- for arrays of NUMBER. -
SQLT_INT
- for arrays of INTEGER (Note: INTEGER it is actually a synonym for NUMBER(38), butSQLT_NUM
type won't work in this case even though they are synonyms). -
SQLT_FLT
- for arrays of FLOAT. -
SQLT_AFC
- for arrays of CHAR. -
SQLT_CHR
- for arrays of VARCHAR2. -
SQLT_VCS
- for arrays of VARCHAR. -
SQLT_AVC
- for arrays of CHARZ. -
SQLT_STR
- for arrays of STRING. -
SQLT_LVC
- for arrays of LONG VARCHAR. -
SQLT_ODT
- for arrays of DATE.
-
Examples
Example #1 oci_bind_array_by_name() example
<?php
$conn = oci_connect("hr", "hrpwd", "localhost/XE");
if (!$conn) {
$m = oci_error();
trigger_error(htmlentities($m['message']), E_USER_ERROR);
}
$create = "CREATE TABLE bind_example(name VARCHAR(20))";
$stid = oci_parse($conn, $create);
oci_execute($stid);
$create_pkg = "
CREATE OR REPLACE PACKAGE ARRAYBINDPKG1 AS
TYPE ARRTYPE IS TABLE OF VARCHAR(20) INDEX BY BINARY_INTEGER;
PROCEDURE iobind(c1 IN OUT ARRTYPE);
END ARRAYBINDPKG1;";
$stid = oci_parse($conn, $create_pkg);
oci_execute($stid);
$create_pkg_body = "
CREATE OR REPLACE PACKAGE BODY ARRAYBINDPKG1 AS
CURSOR CUR IS SELECT name FROM bind_example;
PROCEDURE iobind(c1 IN OUT ARRTYPE) IS
BEGIN
-- Bulk Insert
FORALL i IN INDICES OF c1
INSERT INTO bind_example VALUES (c1(i));
-- Fetch and reverse
IF NOT CUR%ISOPEN THEN
OPEN CUR;
END IF;
FOR i IN REVERSE 1..5 LOOP
FETCH CUR INTO c1(i);
IF CUR%NOTFOUND THEN
CLOSE CUR;
EXIT;
END IF;
END LOOP;
END iobind;
END ARRAYBINDPKG1;";
$stid = oci_parse($conn, $create_pkg_body);
oci_execute($stid);
$stid = oci_parse($conn, "BEGIN arraybindpkg1.iobind(:c1); END;");
$array = array("one", "two", "three", "four", "five");
oci_bind_array_by_name($stid, ":c1", $array, 5, -1, SQLT_CHR);
oci_execute($stid);
var_dump($array);
?>
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-oci-bind-array-by-name.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.