由于有需要,要给Oracle存储过程传递一个二维矩阵,所以研究了一下,也很容易就实现了。
一、对象定义
1.1 表定义
CREATE TABLE "test_proc_array" ( "id" VARCHAR2(255), "name" VARCHAR2(255) )
1.2 Record定义
create or replace type test_proc_array FORCE as object ( -- Author : CLAVES -- Created : 9/18/2017 17:04:58 -- Purpose : -- Attributes "id" NVARCHAR2(255), "name" NVARCHAR2(255) -- Member functions and procedures -- member procedure <ProcedureName>(<Parameter> <Datatype>) );
1.3 嵌套表定义
create or replace type test_proc_array_table is table of test_proc_array;
1.4 存储过程定义
create or replace procedure test_proc(
v_array_table test_proc_array_table
)
as
begin
forall i in 1..v_array_table.count
insert into "test_proc_array"("id","name")
values(v_array_table(i)."id",v_array_table(i)."name");
commit;
end test_proc;
二、运行测试
2.1 运行sql
begin test_proc(test_proc_array_table(test_proc_array('112','432'),test_proc_array('claves','blog')));end;
a
结果:

三、PHP测试
/**
* Oracle 存储过程集合Record参数序列化
* @param $name RecordSet 名称
* @param $params 内容数组
* @return string
*/
public function bind_orc_recordset_by_name($name,$params)
{
return $name.'('.implode(',',$params).')';
}
/**
* Oracle 存储过程Record参数序列化
* @param $name Oracle Record名称
* @param $params Record 内容数组
* @return string
*/
public function bind_orc_record_by_name($name,$params)
{
$iplode="";
foreach($params as $param)
{
if(gettype($param) =="string")
{
$iplode .="'".$param."'".',';
}else{
$iplode .=$param.',';
}
}
$iplode = substr($iplode,0,strlen($iplode)-1);
return $name.'('.$iplode.')';
}
public function main()
{
$tmp1 = array("a1","b1");
$tmp2 = array("a2","b2");
try{
$pdo = DB::getPdo();
$params = $this->bind_orc_recordset_by_name('test_proc_array_table',
array(
$this->bind_orc_record_by_name('test_proc_array',$tmp1),
$this->bind_orc_record_by_name('test_proc_array',$tmp2)
));
$stmt = $pdo->prepare("begin test_proc($params);end;");
$stmt->execute();
}catch(Exception $e)
{
die("Exception:n".var_dump($e->getMessage()).$e->getTrace());
}
}