【发布时间】:2020-06-23 04:43:14
【问题描述】:
我有一个 oracle 函数,它有一个数组作为参数,如下所示:
addGroups($empGroupId, $employees);
它添加了员工组 但是这个数组参数在oracle数据库中被定义为自定义类型如下:
CREATE OR REPLACE TYPE EMPLOYEES."ARR_VAR2" is table of varchar2(32000);
我尝试在 php 中调用这个函数并传递这个数组如下:
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
//recieving parameters
$empGroupId= $request->ID;
$employees= $request->EMPLOYEES;
//establish connection
$conn = oci_connect("EMPLOYEES", "****", "ip/orcl");
//test connection
if ($conn)
{
if($empGroupId!=NULL && $employees!=NULL)
{
$stmt = "begin :resu :=addGroups(:empGroupId,:employees, :result ); end;";
$stid=oci_parse($conn,$stmt);
oci_bind_by_name($stid, ":empGroupId", $empGroupId);
oci_bind_array_by_name($stid, ":employees", $employees, 250, 250, SQLT_VCS );
oci_bind_by_name($stid, ":result", $result, 40);
oci_bind_by_name($stid, ":resu", $resu, 100);
oci_execute($stid);
oci_free_statement($stid);
$result1['output'] = array("result" => $result);
return $result1;
else
{
//connection failed
echo 500;
}
但它返回此错误:
ORA-01458: 可变字符串内的长度无效
我也试过 oci new collection 如下:
$stmt = "begin :resu :=addGroups(:empGroupId,:employees, :result ); end;";
$stid=oci_parse($conn,$stmt);
oci_bind_by_name($stid, ":empGroupId", $empGroupId);
$IDs= oci_new_collection($conn, 'ARR_VAR', 'EMPLOYEES');
foreach($employees as $emp)
{
$IDs->append($emp);
}
oci_bind_by_name($stid, ":employees", $IDs, -1, SQLT_CHR );
oci_bind_by_name($stid, ":result", $result, 40);
oci_bind_by_name($stid, ":resu", $resu, 100);
oci_execute($stid);
oci_free_statement($stid);
$result1['output'] = array("result" => $result);
return $result1;
else
{
//connection failed
echo 500;
}
它给了我这个错误:
警告:oci_new_collection():ORA-22318:输入类型不是数组类型
致命错误:未捕获错误:在布尔值上调用成员函数 append()
有没有办法解决这个问题
提前致谢
【问题讨论】:
-
我还没来得及给出真正的答复。查看The Underground PHP and Oracle Manual 中的 PL/SQL 章节,应该会有所帮助。
标签: php arrays oracle function parameters