Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: oci_bind_array_by_name() example Jump to:  
Category: >> Oracle PL/SQL >> oci_bind_array_by_name() example Bookmark and Share

<< lastnext >>

Snippet Name: oci_bind_array_by_name() example

Description: Binds the PHP array var_array to the Oracle placeholder name , which points to Oracle PL/SQL array. Whether it will be used for input or output will be determined at run-time.

Comment: (none)

Language: PHP, ORACLE
Highlight Mode: PHP
Last Modified: February 27th, 2009

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


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 73 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?