问题描述
如何使用对象类型作为输出参数调用Oracle存储过程?( PLS-00306:调用中错误的参数数目或类型)
你好
我正在尝试从PHP Lumen v6.3调用存储过程,该存储过程在Oracle中定义如下:
PROCEDURE PRC_REGION_LIST(
p_TYPE IN SMALLINT,p_REGION_LIST OUT CT_LST_REGION,p_COD_ERROR OUT NUMBER,p_DES_ERROR OUT VARCHAR2)
IS
v_LST_AUX CT_LST_REGION;
BEGIN
..........
EXCEPTION
WHEN OTHERS THEN
p_COD_ERROR := sqlCODE;
p_DES_ERROR := sqlERRM;
END PRC_REGION_LIST;
create or replace TYPE "CT_LST_REGION" AS TABLE OF T_LST_REGION;
create or replace TYPE "T_LST_REGION" AS OBJECT (
REG_ID NUMBER(10,0),REG_NAME VARCHAR2(50 BYTE)
);
在我的控制器中,我有一个名为 getRegionsPDO() 的函数,其中该过程是手动执行的,另一个函数是 getRegionsYajra() ,其中使用快捷方式执行过程。代码如下:
<?PHP
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use PDO;
class ExampleController extends Controller
{
public function getRegionsPDO()
{
$procedureName = 'PKG_NAME.PRC_REGION_LIST';
$p_TYPE = 1;
$p_REGION_LIST = "-";
$p_COD_ERROR = "-";
$p_DES_ERROR = "-";
$pdo = DB::getPdo();
$pdo = $pdo->prepare("begin {$procedureName}(:p_TYPE,:p_REGION_LIST,:p_COD_ERROR,:p_DES_ERROR); end;");
$pdo->bindParam(':p_TYPE',$p_TYPE,PDO::ParaM_INT);
$pdo->bindParam(':p_REGION_LIST',$p_REGION_LIST,PDO::ParaM_STR);
$pdo->bindParam(':p_COD_ERROR',$p_COD_ERROR,PDO::ParaM_INT);
$pdo->bindParam(':p_DES_ERROR',$p_DES_ERROR,PDO::ParaM_STR);
$pdo->execute();
dd($pdo);
}
public function getRegionsYajra()
{
$procedureName = 'PKG_NAME.PRC_REGION_LIST';
$bindings = [
'p_TYPE' => 1
];
$result = DB::executeProcedure($procedureName,$bindings);
dd($result);
}
}
当我致电 getRegionsPDO() 时,它向我显示以下消息:
<h3 class="trace-class">
<span class="text-muted">(1/1)</span>
<span class="exception_title">
<abbr title="Yajra\Pdo\Oci8\Exceptions\Oci8Exception">Oci8Exception</abbr>
</span>
</h3>
<p class="break-long-words trace-message">
Error Code : 6550
<br>
Error Message : ORA-06550: line 1,column 7:
<br>
PLS-00306: wrong number or types of arguments in call to 'PRC_REGION_LIST'
<br>
ORA-06550: line 1,column 7:
<br>
PL/sql: Statement ignored
<br>
Position : 6
<br>
Statement : begin PKG_NAME.PRC_REGION_LIST(:p_TYPE,:p_DES_ERROR); end;
<br>
Bindings : [1,-,-]
<br>
</p>
当我打电话给 getRegionsYajra() 时,它将显示以下内容:
<h3 class="trace-class">
<span class="text-muted">(1/1)</span>
<span class="exception_title">
<abbr title="Yajra\Pdo\Oci8\Exceptions\Oci8Exception">Oci8Exception</abbr>
</span>
</h3>
<p class="break-long-words trace-message">
Error Code : 6550
<br>
Error Message : ORA-06550: line 1,column 7:
<br>
PL/sql: Statement ignored
<br>
Position : 6
<br>
Statement : begin PKG_NAME.PRC_REGION_LIST(:p_TYPE); end;
<br>
Bindings : [1]
<br>
</p>
我想知道是否有人可以通过我的控制器以正确的方式调用存储过程所需的代码来帮助我。我知道错误出在我的p_REGION_LIST参数中。
系统详细信息
- 操作系统:Windows 10
- PHP v7.4.10
- Laravel版本:Lumen Framework v6.3
- Laravel-OCI8 v6.1.1
- laravel-pdo-via-oci8 v2.1.1
非常感谢您的帮助
解决方法
在您的匿名BEGIN / END块中,使用PHP可以绑定到的简单类型来组成或分解过程的对象参数。
Oracle的免费PDF http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html
的p 209上有一个相关示例。