oci_bind_array_by_name

(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL OCI8 >= 1.2.0)

oci_bind_array_by_nameVincula un array de PHP con un parámetro de un array de Oracle PL/SQL

Descripción

oci_bind_array_by_name(
    resource $statement,
    string $name,
    array &$var_array,
    int $max_table_length,
    int $max_item_length = -1,
    int $type = SQLT_AFC
): bool

Vincular el array de PHP var_array al parámetro de sustitución de Oracle name, el cual apunta a un array de Oracle PL/SQL. Se determinará si será usado para entrada o salida en tiempo de ejecución.

Parámetros

statement

Un identificador de sentencia de OCI válido.

name

El parámetro de sustitución de Oracle.

var_array

Un array.

max_table_length

Establece la longitud máxima para los arrays entrantes y resultantes.

max_item_length

Establece la longitud máxima para los elementos del array. Si no se especifica o es igual a -1, oci_bind_array_by_name() buscará el elemento más largo en el array entrante y usará su longitud como valor.

type

Debería usarse para establecer el tipo de los elementos del arrary de PL/SQL. La lista siguiente muestra los tipos disponibles:

  • SQLT_NUM - para arrays de NUMBER.

  • SQLT_INT - para arrays de INTEGER (Nota: INTEGER es en realidad un sinónimo de NUMBER(38), pero el tipo SQLT_NUM no funcionará en este caso aunque sean sinónimos).

  • SQLT_FLT - para arrays de tipo FLOAT.

  • SQLT_AFC - para arrays de tipo CHAR.

  • SQLT_CHR - para arrays de tipo VARCHAR2.

  • SQLT_VCS - para arrays de tipo VARCHAR.

  • SQLT_AVC - para arrays de tipo CHARZ.

  • SQLT_STR - para arrays de tipo STRING.

  • SQLT_LVC - para arrays de tipo LONG VARCHAR.

  • SQLT_ODT - para arrays de tipo DATE.

Valores devueltos

Devuelve true en caso de éxito o false en caso de error.

Ejemplos

Ejemplo #1 Ejemplo de oci_bind_array_by_name()

<?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);

?>

add a note

User Contributed Notes 3 notes

up
2
Anonymous
14 years ago
This function appears to work with PL/SQL associative arrays (index-by tables) but I was unable to get it to work with PL/SQL varrays
up
-2
Anonymous
16 years ago
Note that it looks like you can't bind a multi-dimensional array with this method. If you try, you'll get a Notice about Array to string conversion, and your PL/SQL will end up with a one-dimensional array filled with the a lot of string values, all saying "Array". :|
up
-4
david dot paper at usu dot edu
13 years ago
We were able to get the example included for the "OCI_BIND_ARRAY_BY_NAME" to work. However, the example is NOT actually binding with a PL/SQL array of any type. It is writing data to an Oracle table named "bind_example". Notice how this table is created. The table does NOT have an array type as one of its fields. Since this is the case, there cannot be any binding to a PL/SQL array because at least one field in the table must be either a VARRAY, NESTED TABLE or ASSOCIATIVE ARRAY data type. We searched the Internet and could not find any examples that actually read from a PL/SQL array type. We were able to get data from a PL/SQL VARRAY data type, but only by using a SELECT statement.
To Top