OCI TABLE OF RECORDS (Oracle 8i)

admin

Administrator
Staff member
Hi all!
I have a stored procedure in Oracle 8i like this:

CREATE OR REPLACE PACKAGE example_Pkg AS

TYPE ex_record_type IS RECORD
(field1 table1.field1%TYPE,
field2 table1.field2%TYPE);

TYPE ex_table_type IS TABLE OF ex_record_type INDEX BY BINARY_INTEGER;
...

PROCEDURE pinsert(ex_table IN OUT ex_table_type);
...

END example_Pkg;
/

CREATE OR REPLACE PACKAGE BODY example_Pkg AS

PROCEDURE pinsert (ex_table IN OUT ex_table_type) IS
i PLS_INTEGER;
BEGIN
FOR i IN ex_table.FIRST..ex_table.LAST LOOP
INSERT INTO table1(field1,field2)
VALUES (ex_table(i).field1,
ex_table(i).field2);
END LOOP;
END;

END example_pkg;
/

And a php script like this:

<?
class ex_record_type { var $field1;
var $field2;
}
...

function insert($conn) {
$tab_rec = new ex_record_type;
$tab_rec->field1="1111";
$tab_rec->field2="OK";

$tab[] = $tab_rec;

$stmt = OCIParse($ligacao,"begin example_pkg.pinsert(:tabela); end;");
OCIBindByName($stmt,":tabela",&$tab,1,OCI_TYPECODE_TABLE);

OCIExecute($stmt);
OCIFreeStatement($stmt);
}
...

?>

And now the error:

Warning: OCIBindByName: ORA-00932: inconsistent datatypes in /home/some/html/test_table.php

I also tried:
$tab = array(0 => array(field1=>"1111",field2=>"OK"));
with
OCIBindByName($stmt,":tabela",&$tab,1);

And gives the error:

Warning: OCIStmtExecute: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'PINSERT' ORA-06550: line 1,
column 7: PL/SQL: Statement ignored in /home/some/html/test_table.php

I know that php supports Ref Cursors and I use that for selects, but now I want a TABLE OF RECORS since I want the same stored procedures for Forms 6i and PHP. And it is more flexible than having a procedure with n fields to insert.

Thanks a lot.

Antonio Pedro
 
Back
Top