PHP运用oci连接方式调用Oracle数据库中的Function(传入和返回的参数都是clob格式)

话不多说,直接上代码:

$string = "[{'PO_NO':'605801','PO_LINE_NO':'1','PO_RELEASE_NO':'1','PO_PART_NO':'682004AF1A','PO_QTY':5,'CUSTOMER_ID':'ACC000G00','PROMISED_DELIVERY_DATE':'20171017','CO_COMPANY':'3909'},{'PO_NO':'605801','PO_LINE_NO':'2','PO_RELEASE_NO':'1','PO_PART_NO':'272106W81C','PO_QTY':45,'CUSTOMER_ID':'ACC000G00','PROMISED_DELIVERY_DATE':'20171017','CO_COMPANY':'3909'},{'PO_NO':'605802','PO_LINE_NO':'1','PO_RELEASE_NO':'2','PO_PART_NO':'682004AF1A','PO_QTY':5,'CUSTOMER_ID':'ACC000G00','PROMISED_DELIVERY_DATE':'20171017','CO_COMPANY':'3909'}]";

$user_name_ck = '';
$pass_ck = '';
$dbConnStr_ck = '//172.28.241.**/TEST';

//连接数据库
try{  
        $dbconn_ck = oci_connect($user_name_ck, $pass_ck, $dbConnStr_ck, 'AL32UTF8')  or die (translateConstant('Database connect failed.').oci_error());
    }catch (ErrorException $ex){ 
echo translateConstant('Could not connect to the database. Please contact your administrator.');    
    }catch(Exception $e){
       
    } 

// 创建一个新的clob描述符
$lobout = oci_new_descriptor($dbconn_ck, OCI_DTYPE_LOB); 

// 传入的字符串
$lobin = $string;
 
$sql_ck = "DECLARE LOBOUT CLOB;BEGIN :LOBOUT := IFSAPP.WEBEDI_INTER_ORDER_RESULT_API.Create_Inter_Order_Json(:LOBIN); END;";

$stid_ck = oci_parse($dbconn_ck, $sql_ck);

oci_bind_by_name($stid_ck,':LOBIN', $lobin);

oci_bind_by_name($stid_ck,':LOBOUT',$lobout, -1 , SQLT_CLOB);

$result_ck = oci_execute($stid_ck);
if(!$result_ck){
echo '%Get data failed!';
return;
}

// 取得返回的json类型字符串
$return_string = $lobout->load();

// 释放clob资源
$lobout -> free();

PHP处理json字符串,格式化为类似于PHP二维数组的格式:

$return_json = json_decode($return_string, true);

取数据方式:

$return_json[0]['PO_NO']

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章