我想在PL/SQL中做一些非常基本的事情,但我一直在擁有...如何將項目推入數組並遍歷它們?如何將項目推入數組並在PL/SQL中遍歷它們?
谷歌搜索似乎暗示使用owa_text.multi_line
;
owa_text.multi_line
就是這種類型的記錄:
/* A multi_line is just an abstract datatype which can hold */
/* large amounts of text data as one piece. */
type multi_line is record
(
rows vc_arr,
num_rows integer,
partial_row boolean
);
要通過vc_arr
迭代,我們必須使用l_array.first.. l_array.last
。但是在嘗試訪問它時出現錯誤。
下面是一個簡單的示例發現負載不同的值到一個數組:
declare
l_persons owa_text.multi_line := owa_text.new_multi();
/* Documentation of owa_text.new_multi(): Standard "make element" routines. */
--function new_multi return multi_line;
l_value_exists boolean := false;
cursor c_get_orders is
select person,
choice
from my_orders;
begin
for i in c_get_orders loop
l_value_exists := false;
for j in l_persons.rows.first.. l_persons.rows.last loop --Fails here,
--PL/SQL: numeric or value error
if l_persons.rows(j) = i.person then
l_value_exists := true;
exit;
end if;
end loop;
if not l_value_exists then
owa_text.add2multi(i.person, l_persons);
end if;
end loop;
for i in l_persons.rows.first.. l_persons.rows.last loop
write_to_log(l_persons.rows(i));
end loop;
end;
我缺少什麼?我該怎麼做呢?
編輯:這是一個腳本才能完成設置,如果它可以幫助效仿的榜樣:
create table my_orders
(
person varchar2(4000 byte),
choice varchar2(4000 byte)
);
insert into my_orders
(person, choice)
values
('Tom', 'Juice');
insert into my_orders
(person, choice)
values
('Jane', 'Apple');
insert into my_orders
(person, choice)
values
('Tom', 'Cake');
insert into my_orders
(person, choice)
values
('Jane', 'Chocolate');
insert into my_orders
(person, choice)
values
('Tom', 'Coffee');
commit;
謝謝,我修復了這個問題。但我仍然得到同樣的錯誤。有任何想法嗎? – Zesty 2014-09-25 12:34:25
new_multi()方法的功能是什麼? – Aramillo 2014-09-25 12:38:41
這是一個函數,用於初始化multi_line/*標準「make元素」例程。 */ 函數new_multi返回multi_line; – Zesty 2014-09-25 12:39:47