2

我在 pl/sql 中创建了一个返回 varchar2 表的函数,我在 sqldeveloper 上对其进行了测试,我知道它可以工作。但是现在,我想用一个 php 项目来检索这个表。首先,我试过这个

oci_bind_by_name($stid,":returnValue",$returnValue);

但我得到了这个:

 Warning: oci_execute() [function.oci-execute]: ORA-06550: line 2, column 41: PLS-00382: expression is of wrong type ORA-06550: line 2, column 25: PL/SQL: Statement ignored in C:\xampp\htdocs\BCN_REQUETEUR\index.php on line 15

然后我尝试了这个

 oci_bind_array_by_name($stid,":returnValue",$returnValue,250,250);

但我遇到了同样的错误。那么,我们如何在 php 中检索这个 varchar2 表呢?谢谢

编辑:我终于成功了,我没有使用 pl/sql 函数,而是使用了一个带有“输出参数”的过程,然后在 php 端:

 $query = "BEGIN 
             ecrire_requete(30, :thesechar); 
           END;";
 $stid = oci_parse($conn, $query);
 $tabvars = oci_new_collection($conn,'MYTABLETYPE');
 oci_bind_by_name($stid, ':thesechar', $tabvars, -1, SQLT_NTY);
 oci_execute($stid, OCI_DEFAULT);
 for ($i = 0;$i < count($tabvars);$i++) 
 { 
     echo "<br>".$tabvars->getElem($i);
 }
4

1 回答 1

0

我想你可以像这样使用 pl/sql....我像你一样使用了相同的 pl/sql 脚本,但不是 Preprocedure

<?php
$dbServerName = 'localhost';
$dbName = 'CGG1';
$dbUserName = 'SYSTEM';
$dbPassword = 'admin';

$port = 1521;

$c2 = oci_connect($dbUserName, $dbPassword, "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = $dbServerName)(PORT = $port)))(CONNECT_DATA=(SID=$dbName)))");

if($c2)
{
    $v = "DECLARE
    --var_num1 number; 
    --var_num2 number; 
    BEGIN 
        --var_num1 := 100; 
        --var_num2 := 200; 
        DECLARE 
        var_mult number; 
        BEGIN 
            -- AMATIA_TIPO_ADMIN;
            delete from AMATIA_TIPO_ADMIN;
            Insert into AMATIA_TIPO_ADMIN (ID_TIPO_ADMIN,NOMBRE) values (8,'Vista Contratista');
            Insert into AMATIA_TIPO_ADMIN (ID_TIPO_ADMIN,NOMBRE) values (5,'Vista Matriz legal');
            Insert into AMATIA_TIPO_ADMIN (ID_TIPO_ADMIN,NOMBRE) values (6,'Superadministrador');
            Insert into AMATIA_TIPO_ADMIN (ID_TIPO_ADMIN,NOMBRE) values (7,'Vista Gestor');

            select max(ID_TIPO_ADMIN) into var_mult from AMATIA_TIPO_ADMIN;

            execute immediate
            'DROP SEQUENCE SEQ_AMATIA_TIPO_ADMIN';
            var_mult := var_mult + 1 ;
            execute immediate
            'CREATE SEQUENCE SEQ_AMATIA_TIPO_ADMIN INCREMENT BY 1 START WITH '|| var_mult || ' MAXVALUE 9999999999999999999999999999 MINVALUE 0 CACHE 20';
        END; 
    END; 
    ";
    $stid = oci_parse($c2, $v);

    $checkExe = oci_execute($stid);

    echo $checkExe . "<hr>";
}
else
{
    echo "NOT SUCCESS";
}
?>
于 2013-09-02T13:10:15.593 回答