如何在PHP中调用一个返回大型xml的函数

时间:2018-02-17 15:22:27

标签: php oracle

$sql = <<<SQL
declare 
x xmltype;
x1 number;
x2 varchar2(4000);
x4 varchar2(4000);
x5 number;
x6 varchar2(4000);
a long;
begin
:x := ws_circus.get_stations(318461,'ro',0,'autogara',:x5,x6);
end;
SQL;

这是我的功能

            $statement=oci_parse($connection['link'] , $sql);
            oci_bind_by_name($statement, ':x', $a ,-1);???????????????
            oci_bind_by_name($statement, ':x5', $x5);
            oci_execute($statement);

如何从Oracle调用返回大型xml

的函数

1 个答案:

答案 0 :(得分:1)

查看XML章节中的技巧 The Underground PHP and Oracle Manual。您需要创建一个PL / SQL或其他代码的匿名块,以使用XMLTYPE.GETCLOBVAL()将XML转换为LOB。然后,您可以在PHP OCI8中使用LOB函数。

例如

drop table mytab;
create table mytab (id number, data xmltype);
insert into mytab (id, data) values (1, '<something>mydata</something>');

create or replace function myf(p_id number) return xmltype as
  loc xmltype;
begin
  select data into loc from mytab where id = p_id;
  return loc;
end;
/

create or replace function myf_wrapper(p_id number) return clob as
begin
  return myf(p_id).getclobval();
end;
/

您可以使用包装函数myf_wrapper或匿名块,如:

<?php

$c = oci_connect('cj', 'cj', 'localhost/orclpdb');

$bd = oci_new_descriptor($c, OCI_D_LOB);
$s = oci_parse($c, "begin :bv := myf_wrapper(1); end;");
oci_bind_by_name($s, ":bv", $bd, -1, OCI_B_CLOB);
oci_execute($s);

echo htmlentities($bd->load()) . "\n";
$bd->free();

$bd = oci_new_descriptor($c, OCI_D_LOB);
$s = oci_parse($c, "begin :bv := myf(1).getclobval(); end;");
oci_bind_by_name($s, ":bv", $bd, -1, OCI_B_CLOB);
oci_execute($s);

echo htmlentities($bd->load()) . "\n";
$bd->free();

?>