错误:将数组传递给另一个过程时出现“错误的数字,类型或参数”

时间:2019-01-02 13:19:14

标签: oracle plsql

我想将数组作为论据传递给另一个过程。.两个都在同一个程序包中。.在下面的这种情况下,演示数组被传递..收到错误:“ PLS-00306错误的数字或类型的参数显示。”

CREATE or REPLACE package WSH_Delivery_Detail_Shipment is

type Result IS VARRAY(8) OF INTEGER;
p_result Result:=Result();

PROCEDURE CreateShipment(p_delivery_detail_interface_id IN WSH_DEL_DETAILS_INTERFACE.DELIVERY_DETAIL_INTERFACE_ID%TYPE,p_status OUT String);
PROCEDURE CreateShipmentLines(p_result IN RESULT);

END WSH_Delivery_Detail_Shipment;
/


CREATE OR REPLACE package body WSH_Delivery_Detail_Shipment as

PROCEDURE CreateShipment(p_delivery_detail_interface_id IN WSH_DEL_DETAILS_INTERFACE.DELIVERY_DETAIL_INTERFACE_ID%TYPE,p_status OUT String)

IS

CURSOR wddi_cur IS SELECT * FROM WSH_DEL_DETAILS_INTERFACE WHERE DELIVERY_DETAIL_INTERFACE_ID=p_delivery_detail_interface_id;
wddi_record WSH_DEL_DETAILS_INTERFACE%ROWTYPE;

type Result IS VARRAY(8) OF INTEGER;
p_result Result:=Result(1,1,1,1,1,1,1,1);

BEGIN

OPEN wddi_cur;

LOOP

.. Some few select queries>>>>

WSH_Delivery_Detail_Shipment.CreateShipmentLines(p_result); // Calling procedure and passing array



END LOOP;
CLOSE wddi_cur;
END CreateShipment;

procedure CreateShipmentLines(p_result IN RESULT)

is

BEGIN

....Some select queries

END CreateShipmentLines;
END WSH_Delivery_Detail_Shipment;
/

2 个答案:

答案 0 :(得分:3)

您声明了两种名为Result的类型。 CreateShipmentLines需要第一个,但您正在传递第二个。

删除第二个声明(type Result is ...中以'CreateShipment'开始的行)应该可以解决此问题。

答案 1 :(得分:1)

From the documentation

  

包装规范中定义的集合类型与相同定义的本地或独立集合类型不兼容。

尽管在您的情况下,这两个声明都在包中,但是第二个声明在CreateShipment过程定义中是局部的,因此仍然与包规范中的声明不兼容。尽管它们对您来说看起来相同,但是对于Oracle编译器,它们是不同的类型。

因此,正如@WilliamRobertson所说,您只需更改过程即可使用规范中声明的类型:

CREATE OR REPLACE package body WSH_Delivery_Detail_Shipment as

PROCEDURE CreateShipment(p_delivery_detail_interface_id IN WSH_DEL_DETAILS_INTERFACE.DELIVERY_DETAIL_INTERFACE_ID%TYPE,p_status OUT String)
IS

  CURSOR wddi_cur IS SELECT * FROM WSH_DEL_DETAILS_INTERFACE WHERE DELIVERY_DETAIL_INTERFACE_ID=p_delivery_detail_interface_id;
  wddi_record WSH_DEL_DETAILS_INTERFACE%ROWTYPE;

  -- type Result IS VARRAY(8) OF INTEGER; -- remove this
  p_result Result:=Result(1,1,1,1,1,1,1,1); -- now uses type from specification

BEGIN
  ...

作为一个单独的问题,程序包规范中的p_result Result:=Result();也与该过程定义中声明的p_result变量完全独立。从您显示的内容来看,全局p_result从未使用过,这使其变得多余;但是这也会使您的软件包stateful变得不希望使用-稍后可能导致不必要的“ ORA-04068:软件包的现有状态已被丢弃”错误。因此,您可能希望从规范中删除该全局变量声明。 (当然,如果您确实使用了该全局变量,并且包必须具有状态,则忽略此部分...)