我需要什么
我需要从存储过程中获取json数据
我有很多谷歌,但无法解决问题
源代码
$param1 = 'abc';
$param2 = '79';
$param3 = 'Y';
$param4 = 121221;
$sql1='CALL web_demo.wwv_json_data.dashboard(:param1, :param2 , :param3, :param4,@p_json)';
$qb = $em->getConnection()->prepare($sql1);
$qb->bindParam('param1', $param1, \PDO::PARAM_INPUT_OUTPUT, 4000);
$qb->bindParam('param2', $param2, \PDO::PARAM_INPUT_OUTPUT, 4000);
$qb->bindParam('param3', $param3, \PDO::PARAM_INPUT_OUTPUT, 1);
$qb->bindParam('param4', $param4, \PDO::PARAM_INPUT_OUTPUT, 4000);
$st=$qb->execute();
$st->closeCursor();
$stmt = $qb->query("SELECT @p_json as json");
$result = $qb->fetchAll(PDO::FETCH_ASSOC);
程序
PROCEDURE dashboard
(p_customer_id IN VARCHAR2 DEFAULT NULL, p_user_id IN VARCHAR2 DEFAULT NULL, p_staff IN VARCHAR2 DEFAULT NULL,p_random IN VARCHAR2 DEFAULT NULL,out p_json clob)
END dashboard
oracle sql开发人员代码
DECLARE
v clob;
BEGIN
web_demo.wwv_json_data.dashboard('abc','79','Y',121221,v);
dbms_output.put_line(v);
END;
返回json
{"data":[{"open_log":46,"to_m":34,"to_clien":12,"to_m":0}]}
错误
An exception occurred while executing 'CALL web_demo.wwv_json_data.dashboard(:param1, :param2 , :param3, :param4,@p_json)':
SQLSTATE[HY000]: General error: 936 OCIStmtExecute: ORA-00936: missing expression
(ext\pdo_oci\oci_statement.c:148)
我需要什么
我正在访问像这样的变量
$stmt = $qb->query("SELECT @p_json as json");
$result = $qb->fetchAll(PDO::FETCH_ASSOC);
任何人都可以通过在oracle和symfony2中使用out变量来帮助我获取数据。
答案 0 :(得分:1)
最终我在经过长时间的斗争后得到了解决方案
代码段
<?php
$userName = ""; $password = ""; $dtabasePort = "1521"; $serverName = "someip";
$c = oci_connect($userName, $password, '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = mtldb11gvm4)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME =dbname) (SID =dbname)))');
$sql = 'BEGIN web_demo.wwv_json_data.dashboard(:param1, :param2 , :param3, :param4,:param5); END;';
$stmt = oci_parse($c,$sql);
$id;
oci_bind_by_name($stmt,":param1",$param1,32);
oci_bind_by_name($stmt,":param2",$param2,500);
oci_bind_by_name($stmt,":param3",$param3,32);
oci_bind_by_name($stmt,":param4",$param4,200);
oci_bind_by_name($stmt,":param5",$id,200);
// Explained in the next example... (use an empty value for now)
//$param5 = oci_new_collection($c,'LIST_OF_NUMBERS');
//oci_bind_by_name($stmt,':param5',$param5,32,OCI_B_SQLT_NTY);
// Create a new lob descriptor object
// Execute the statement but do not commit
oci_execute($stmt, OCI_DEFAULT);
print_r($id);
// Everything OK so commit
oci_commit($c);
if (!$c) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
else {
print "Connected to Oracle!";
}
print_r($c);
?>