php調用oracle帶有out參數的存儲過程

//入參
$in1 = '2017-01-01'; //必填
$in2 = '2017-08-01'; //必填
$in3 = ''; //選填html

$tns = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = dbname) (SID = dbname)))';
$conn = oci_connect ('user' , 'password' ,$tns,'utf8');
if (! $conn ) {
  $e = oci_error ();
  trigger_error ( htmlentities ( $e [ 'message' ]), E_USER_ERROR );
}
$curs = oci_new_cursor($conn);
$stmt = oci_parse($conn, "begin PACKAGE_NAME.PROCEDURE_NAME(:IN1,:IN2,:IN3,:OUT1); end;");
oci_bind_by_name ( $stmt , ':IN1' , $in1 );
oci_bind_by_name ( $stmt , ':IN2' , $in2 );
oci_bind_by_name ( $stmt , ':IN3' , $in2 );
oci_bind_by_name($stmt, ":OUT1", $curs, -1, SQLT_RSET);
oci_execute($stmt);
oci_execute($curs,OCI_DEFAULT);fetch

while (( $row = oci_fetch_row ( $curs )) != false ) {
  var_dump($row);
}
oci_free_statement($stmt);
oci_free_statement($curs);
oci_close($conn);spa

 

紅色部分須要注意htm

1,'utf8'注意字符集,若是入參中有中文,沒有指定字符集,可能會影響結果。ci

2,:IN3雖然該參數爲可選參數,調用時也爲空字符串,可是調用時必須帶上該參數,不然得不到想要的結果。字符串

3,$curs, SQLT_RSET 注意出參的類型,存儲過程當中什麼類型就用相應類類型去接收。
it

相關文章
相關標籤/搜索