1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<refentry id="function.oci-bind-array-by-name">
<refnamediv>
<refname>oci_bind_array_by_name</refname>
<refpurpose>
Binds PHP array to Oracle PL/SQL array by name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>oci_bind_array_by_name</methodname>
<methodparam><type>resource</type><parameter>stmt</parameter></methodparam>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
<methodparam><type>array</type><parameter role="reference">var_array</parameter></methodparam>
<methodparam><type>int</type><parameter>max_table_length</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>max_item_length</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>type</parameter></methodparam>
</methodsynopsis>
<note>
<para>
This function is available since OCI8 release 1.2 and PHP release 5.1.2.
</para>
</note>
<para>
<function>oci_bind_array_by_name</function> binds the PHP array
<parameter>var_array</parameter> to the Oracle placeholder
<parameter>name</parameter>, which points to Oracle PL/SQL array.
Whether it will be used for input or output will be determined at
run-time. The <parameter>max_table_length</parameter>
parameter sets the maximum length both for incoming and result arrays.
Parameter <parameter>max_item_length</parameter> sets maximum length for
array items. If <parameter>max_item_length</parameter> was not specified
or equals to -1, <function>oci_bind_array_by_name</function> will use
find the longest element in the incoming array and will use it as
maximum length for array items. <parameter>type</parameter> parameter
should be used to set the type of PL/SQL array items. See list of
available types below.
</para>
<para>
<itemizedlist>
<listitem>
<para>
<constant>SQLT_NUM</constant> - for arrays of NUMBER.
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_INT</constant> - for arrays of INTEGER (Note: INTEGER
it is actually a synonym for NUMBER(38), but
<constant>SQLT_NUM</constant> type won't work in this case even
though they are synonyms).
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_FLT</constant> - for arrays of FLOAT.
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_AFC</constant> - for arrays of CHAR.
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_CHR</constant> - for arrays of VARCHAR2.
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_VCS</constant> - for arrays of VARCHAR.
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_AVC</constant> - for arrays of CHARZ.
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_STR</constant> - for arrays of STRING.
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_LVC</constant> - for arrays of LONG VARCHAR.
</para>
</listitem>
<listitem>
<para>
<constant>SQLT_ODT</constant> - for arrays of DATE.
</para>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title><function>oci_bind_array_by_name</function>example</title>
<programlisting role="php">
<![CDATA[
<?php
$c = oci_connect("scott", "tiger");
$create = "CREATE TABLE bind_example(name VARCHAR(20))";
$statement = oci_parse($c, $create);
oci_execute($statement);
$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;";
$statement = oci_parse($c, $create_pkg);
oci_execute($statement);
$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
FOR i IN 1..5 LOOP
INSERT INTO bind_example VALUES (c1(i));
END LOOP;
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;";
$statement = oci_parse($c, $create_pkg_body);
oci_execute($statement);
$statement = oci_parse($c, "BEGIN ARRAYBINDPKG1.iobind(:c1); END;");
$array = array("one", "two", "three", "four", "five");
oci_bind_array_by_name($statement, ":c1", $array, 5, -1, SQLT_CHR);
oci_execute($statement);
var_dump($array);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|