在包之间传递关联数组作为参数

发布于 2024-11-03 05:49:01 字数 650 浏览 5 评论 0原文

我有两个单独的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无名指的心愿 2024-11-10 05:49:01

是的,这肯定是可能的。

很难解释为什么在没有包规范示例的情况下会收到错误,但一般来说,要将用户定义的类型作为参数传递,您应该使用 定义类型 DDL,或在包规范中定义类型。

我想您想要后一种变体:)

所以这里有一个示例:

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;
/

您可以在任何 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:

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 not in SQL.

躲猫猫 2024-11-10 05:49:01

“数组定义为:...在两者中
封装的规格。”

这是问题的根源。PL/SQL 将两个单独的声明视为两个不同的对象,即使两种类型具有相同的签名。因此,当您调用此方法时,引擎会抛出错误:

package2.rollup_to_15(chanList)

您的代码已将 chanList 变量定义为package1.list_tab 但该过程需要一个 package2.list_tab 类型的变量。

最简单的解决方案是仅在 PACKAGE2 中声明 LIST_TAB,并更改 PACKAGE1,以便正确声明 chanList。 。

"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:

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.

The simplest solution is to declare LIST_TAB just in PACKAGE2, and chnage PACKAGE1 so that chanList is declared appropriately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文