在 PLSQL 中返回两个列表
我正在尝试将 3 个 VARRAYS/COLLECTIONS 的列表返回到我的应用程序。但我遇到了麻烦,认为我要么错误地实施了解决方案,
create or replace
PROCEDURE "GENERATE_PEOPLE"
(
-- In this example pi_string will be "This.is.a.test"
pi_string IN VARCHAR2 ,
po_firstnames OUT VARRAY ,
po_lastnames OUT VARRAY ,
po_descriptions OUT VARRAY ,
po_error_code OUT VARCHAR2 ,
po_error_message OUT VARCHAR2
)
IS
CURSOR people_cursor IS SELECT firstname, lastname, description FROM people;
BEGIN
FOR person_rec IN people_cursor
LOOP
-- This is where I am trying to return 3 collections of po_firstnames, po_lastnames, po_descriptions
-- The print statements below print out exactly what it is I am trying to return!
dbms_output.put_line('Firstname: ' || person_rec.firstname);
dbms_output.put_line('Lastname: ' || person_rec.lastname);
dbms_output.put_line('Description: ' || pi_string || person_rec.description);
-- This is where the values would be added to the list/array/collection
po_firstnames(num?) := person_rec.firstname;
po_lastnames(num?) := person_rec.lastname;
po_descriptions(num?) := pi_string || person_rec.description;
END LOOP;
RETURN;
END;
非常感谢任何帮助
Oracle 10g
我这样称呼它:
DECLARE
TYPE po_firstnames AS vc2_array;
TYPE po_lastnames AS vc2_array;
TYPE po_descriptions AS vc2_array;
po_error_code VARCHAR2(50);
po_error_message VARCHAR2(50);
BEGIN
GENERATE_PEOPLE
(
'This.is.a.test' ,
po_firstnames ,
po_lastnames ,
po_descriptions ,
po_error_code ,
po_error_message
);
END;
I am trying to return a list of 3 VARRAYS/COLLECTIONS to my application. I am having trouble though, think I am either implementing the solution incorrectly
create or replace
PROCEDURE "GENERATE_PEOPLE"
(
-- In this example pi_string will be "This.is.a.test"
pi_string IN VARCHAR2 ,
po_firstnames OUT VARRAY ,
po_lastnames OUT VARRAY ,
po_descriptions OUT VARRAY ,
po_error_code OUT VARCHAR2 ,
po_error_message OUT VARCHAR2
)
IS
CURSOR people_cursor IS SELECT firstname, lastname, description FROM people;
BEGIN
FOR person_rec IN people_cursor
LOOP
-- This is where I am trying to return 3 collections of po_firstnames, po_lastnames, po_descriptions
-- The print statements below print out exactly what it is I am trying to return!
dbms_output.put_line('Firstname: ' || person_rec.firstname);
dbms_output.put_line('Lastname: ' || person_rec.lastname);
dbms_output.put_line('Description: ' || pi_string || person_rec.description);
-- This is where the values would be added to the list/array/collection
po_firstnames(num?) := person_rec.firstname;
po_lastnames(num?) := person_rec.lastname;
po_descriptions(num?) := pi_string || person_rec.description;
END LOOP;
RETURN;
END;
Any help is greatly appreciated
Oracle 10g
And I am calling it as such:
DECLARE
TYPE po_firstnames AS vc2_array;
TYPE po_lastnames AS vc2_array;
TYPE po_descriptions AS vc2_array;
po_error_code VARCHAR2(50);
po_error_message VARCHAR2(50);
BEGIN
GENERATE_PEOPLE
(
'This.is.a.test' ,
po_firstnames ,
po_lastnames ,
po_descriptions ,
po_error_code ,
po_error_message
);
END;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VARRAY 不能直接用作参数或变量的类型。相反,您需要创建一个像这样的 VARRAY 类型(例如):
那么:
通常我会使用 TABLE 而不是 VARRAY,因为使用 TABLE 您不必指定最大元素数:
然后可以像这样分配值this 在你的循环中:
但是这样做会更有效:
VARRAY cannot be used directly as the type of a parameter or variable. Instead you need to create a TYPE that is a VARRAY like this (e.g.):
then:
Generally I would use TABLE rather than VARRAY, bacause with TABLE you do not have to specify a maximum number of elements:
The values can then be assigned like this in your loop:
However it would be more efficient to do this: