oracle 在包之间传递关联数组作为参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5778640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing an associative array as a parameter between packages
提问by DaveKub
I've got two separate Oracle (v9.2) PL/SQL packages and I'm trying to pass an associative array (ie, index-by table) from a procedure in package1, as a parameter to a procedure in package2. Is this possible? I keep getting PLS-00306: wrong number or types of arguments in call to 'ROLLUP_TO_15'
when I compile package1.
我有两个单独的 Oracle (v9.2) PL/SQL 包,我试图将一个关联数组(即索引表)从包 1 中的过程作为参数传递给包 2 中的过程。这可能吗?PLS-00306: wrong number or types of arguments in call to 'ROLLUP_TO_15'
当我编译 package1 时,我不断收到。
The array is defined as:
数组定义为:
type list_tab is table of number(10)
index by binary_integer;
in both package's spec. In the procedure in package1, I'm calling the second package as package2.rollup_to_15(chanList);
That's the line I get the compile error on (chanList
is a variable of type list_tab
).
在两个包的规格中。在 package1 中的过程中,我正在调用第二个包,因为package2.rollup_to_15(chanList);
这是我在 ( chanList
is a variable of type list_tab
)上得到编译错误的那一行。
In package2, the procedure is defined as:
在 package2 中,程序定义为:
procedure rollup_to_15(channels in list_tab) is
I'm guessing that my problem is that the type is defined separately in each package, because I can pass the `chanList' variable to other procedures within the first package without any problems.
我猜我的问题是类型是在每个包中单独定义的,因为我可以将 `chanList' 变量传递给第一个包中的其他过程而没有任何问题。
So, is it possible to pass an associative array between packages? And if so, how?
那么,是否可以在包之间传递关联数组?如果是这样,如何?
Dave
戴夫
回答by andr
Yes, it's possible for sure.
是的,这是肯定的。
It's hard to explain why do you receive error without package specs samples, but in general to pass a user-defined type as a parameter you should either with define type DDL, or defining the type in package spec.
很难解释为什么在没有包规范示例的情况下会收到错误,但通常要将用户定义的类型作为参数传递,您应该使用定义类型 DDL或在包规范中定义类型。
I suppose you want the latter variant :)
我想你想要后一种变体:)
So here're an example:
所以这是一个例子:
create or replace package TestPackage_1
as
type TTestType is table of varchar2(1) index by varchar2(1);
end TestPackage_1;
/
create or replace package TestPackage_2
as
procedure Dummy(aParam TestPackage_1.TTestType);
end TestPackage_2;
/
You can use TTestType
type in any PL/SQL block, but notin SQL.
您可以TTestType
在任何 PL/SQL 块中使用类型,但不能在 SQL 中使用。
回答by APC
"The array is defined as: ... in both package's spec."
“该数组定义为:......在两个包的规范中。”
This is the source of your problem. PL/SQL regards two separate declarations as two different objects, even though both types have an identical signature. Consequently the engine hurls when you call this:
这是您问题的根源。PL/SQL 将两个单独的声明视为两个不同的对象,即使这两种类型具有相同的签名。因此,当你调用它时引擎会抛出:
package2.rollup_to_15(chanList)
Your code has defined the chanList variable as package1.list_tab
but the procedure is expecting a variable of type package2.list_tab
.
您的代码已将 chanList 变量定义为,package1.list_tab
但该过程需要一个类型为 的变量package2.list_tab
。
The simplest solution is to declare LIST_TAB just in PACKAGE2, and chnage PACKAGE1 so that chanList is declared appropriately.
最简单的解决方案是仅在 PACKAGE2 中声明 LIST_TAB,并更改 PACKAGE1,以便正确声明 chanList。