在包之间传递关联数组作为参数
我有两个单独的 Oracle (v9.2) PL/SQL 包,并且我试图将 package1 中的过程中的关联数组(即索引表)作为参数传递给 package2 中的过程。这可能吗?当我编译 package1 时,我不断收到 PLS-00306:调用“ROLLUP_TO_15”时参数数量或类型错误
。
定义为:
type list_tab is table of number(10)
index by binary_integer;
该数组在两个包的规范中 在 package1 中的过程中,我将第二个包调用为 package2.rollup_to_15(chanList);
这是我收到编译错误的行(chanList
是一个变量输入list_tab
)。
在 package2 中,该过程定义为:
procedure rollup_to_15(channels in list_tab) is
我猜我的问题是类型是在每个包中单独定义的,因为我可以将“chanList”变量传递给第一个包中的其他过程,没有任何问题。
那么,是否可以在包之间传递关联数组?如果是这样,怎么办?
戴夫
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.
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
).
In package2, the procedure is defined as:
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.
So, is it possible to pass an associative array between packages? And if so, how?
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这肯定是可能的。
很难解释为什么在没有包规范示例的情况下会收到错误,但一般来说,要将用户定义的类型作为参数传递,您应该使用 定义类型 DDL,或在包规范中定义类型。
我想您想要后一种变体:)
所以这里有一个示例:
您可以在任何 PL/SQL 块中使用
TTestType
类型,但在 SQL 中不能。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.
I suppose you want the latter variant :)
So here're an example:
You can use
TTestType
type in any PL/SQL block, but not in SQL.这是问题的根源。PL/SQL 将两个单独的声明视为两个不同的对象,即使两种类型具有相同的签名。因此,当您调用此方法时,引擎会抛出错误:
您的代码已将 chanList 变量定义为
package1.list_tab
但该过程需要一个package2.list_tab
类型的变量。最简单的解决方案是仅在 PACKAGE2 中声明 LIST_TAB,并更改 PACKAGE1,以便正确声明 chanList。 。
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:
Your code has defined the chanList variable as
package1.list_tab
but the procedure is expecting a variable of typepackage2.list_tab
.The simplest solution is to declare LIST_TAB just in PACKAGE2, and chnage PACKAGE1 so that chanList is declared appropriately.