使用 oci_new_collection 访问包内定义的 varray 类型

发布于 2024-10-15 16:21:52 字数 1033 浏览 9 评论 0原文

您好,我正在尝试将变量从 PHP 传递到 Oracle。我正在使用 OCI8,并且之前曾使用变量作为存储过程中的参数,并在编译时创建这些变量的类型。所以在PHP端创建集合实例时,我们可以直接提及集合名称。

例如:

$my_coll = oci_new_collection($c, 'MY_ARRAY');

其中 MY_ARRAY 是我在 Oracle 实例中声明的 varray 类型。

create or replace type MY_ARRAY as varray(100) of varchar2(20);

因此,当我在包外部创建它们时,类型会被编译并在执行期间准备就绪。

如果我从包中执行此操作,则会收到错误

PHP警告:oci_new_collection() [function.oci-new-collection]:OCI-22303:类型“”。“my_pack.my_array_type”未找到

我的包头看起来像这样

create or replace
PACKAGE my_pack
AS
   TYPE my_array_type is VARRAY(200) of varchar2(20);
    my_arr my_array_type;

    function my_func(
    in_id number,
    in_arr my_array_type    
    )
    return number;

end my_pack;

现在,当我从 PHP 进行调用以创建集合实例时,这就是我所做的

$my_collection = oci_new_collection($connect,'my_pack.my_array_type');

现在我收到警告类型未找到。

我的问题是,我该如何调用包中的 varray 类型???我将其作为 package.type_name 执行,但收到​​警告说找不到类型。

Hello I am trying to pass in varrays from PHP to Oracle. I am using OCI8 and have earlier worked with varrays as arguments in stored procedures, and on compilation the types of those varrays are created. So while making collection instance on the PHP end, we can directly mention the collection name.

Ex:

$my_coll = oci_new_collection($c, 'MY_ARRAY');

where MY_ARRAY would be the varray type I had declared in the Oracle instance.

create or replace type MY_ARRAY as varray(100) of varchar2(20);

So when I create them outside a package, the type is compiled and would be ready during execution.

If I do that from packages, I am getting back the error

PHP Warning: oci_new_collection() [function.oci-new-collection]: OCI-22303: type ""."my_pack.my_array_type" not found

My package header would look like this

create or replace
PACKAGE my_pack
AS
   TYPE my_array_type is VARRAY(200) of varchar2(20);
    my_arr my_array_type;

    function my_func(
    in_id number,
    in_arr my_array_type    
    )
    return number;

end my_pack;

Now when I make a call from PHP to create an instance of collection, this is the way I do

$my_collection = oci_new_collection($connect,'my_pack.my_array_type');

Now I get the warning type not found.

My question is, how would I have to call the varray type that is in the package??? I am doing it as package.type_name, but I am getting the warning that says type not found.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

旧时浪漫 2024-10-22 16:21:52

尝试以大写形式传递架构和类型名

oci_new_collection($connect,'MY_PACK.MY_ARRAY_TYPE', 'MY_SCHEMA')

Upd。

我发现 OCI Reference 中没有任何限制,但 PL\SQL Reference 提供了更多信息:

在 a 中定义的 PL/SQL 复合类型
封装规格不兼容
具有相同定义的本地或
独立存储类型

同样来自 PL\SQL Reference(表 5-1),所有类型的集合都有限制。例如在包级别声明的 VARRAY:

只有在以下情况下才可以是 ADT 属性数据类型:
在架构级别定义

Try to pass schema and typename in uppercase

oci_new_collection($connect,'MY_PACK.MY_ARRAY_TYPE', 'MY_SCHEMA')

Upd.

I've found no limitations in OCI Reference, but PL\SQL Reference was more informative:

A PL/SQL composite type defined in a
package specification is incompatible
with an identically defined local or
standalone stored type

Also from PL\SQL Reference (Table 5-1) all sorts of collections have restrictions. For example VARRAY declared at package level:

Can Be ADT Attribute Data Type only if
defined at schema level

滥情稳全场 2024-10-22 16:21:52

这对我有用:

$in_arr = array('1','2','3');    
$s = ociparse($database, "BEGIN my_pack.my_func(:in_id, :in_arr); END;");
oci_bind_by_name($s, ':in_id', $in_id, 32 );
oci_bind_array_by_name($s, ':in_arr', $in_arr, 250, -1, SQLT_VCS);

如果您需要:

$out_arr = array(); //OUT   
$s = ociparse($database, "BEGIN my_pack.my_func(:in_id, :out_arr); END;") ;
oci_bind_by_name($s, ':in_id', $in_id, 32);
oci_bind_array_by_name($s,':out_arr', $out_arr, 250, 250, SQLT_VCS);
                                                     // change -1 for 250

This works for me:

$in_arr = array('1','2','3');    
$s = ociparse($database, "BEGIN my_pack.my_func(:in_id, :in_arr); END;");
oci_bind_by_name($s, ':in_id', $in_id, 32 );
oci_bind_array_by_name($s, ':in_arr', $in_arr, 250, -1, SQLT_VCS);

If you need out:

$out_arr = array(); //OUT   
$s = ociparse($database, "BEGIN my_pack.my_func(:in_id, :out_arr); END;") ;
oci_bind_by_name($s, ':in_id', $in_id, 32);
oci_bind_array_by_name($s,':out_arr', $out_arr, 250, 250, SQLT_VCS);
                                                     // change -1 for 250
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文