我如何在 pl/sql 的列中向我的 varray 列表添加一个值?
How i can add one more value to my varray list in a column in pl/sql?
我正在尝试使用 multiset union all 向我的名为 burse
的 varray 数字列表添加一个值,但我收到此错误。 [1
但是当我插入一个值时它起作用了。示例:
我做错了什么?
这就是我声明和插入列
的方式
这应该有效...
update student
set istoric = istoric multiset union all bure(42, 23)
where id = 1
... 除了您现在使用的是 VARRAY(而不是嵌套的 table,您曾使用 in your previous question)。所以你得到一个错误信息:
ORA-00932: inconsistent datatypes: expected UDT got BURE
原因是,according to the documentation:
"While nested tables can also be changed in a piecewise fashions, varrays cannot....However, you cannot update or delete individual varray elements directly with SQL; you have to select the varray from the table, change it in PL/SQL, then update the table to include the new varray." (emphasis mine)
这是因为 VARRAY 是有序集,而嵌套表不是。除非有维护元素顺序的明确要求,否则最好使用嵌套表而不是 Varray:它们只是更方便。
下面是使用 PL/SQL 更新 Varray 的方法:
declare
lv bure;
cnt pls_integer;
begin
select istoric into lv
from student
where id = 1;
cnt := lv.count();
lv.extend();
lv(cnt+1) := 23 ;
lv.extend();
lv(cnt+2) := 69 ;
update student
set istoric = lv
where id = 1;
end;
/
我正在尝试使用 multiset union all 向我的名为 burse
的 varray 数字列表添加一个值,但我收到此错误。 [
但是当我插入一个值时它起作用了。示例:
我做错了什么?
这就是我声明和插入列
这应该有效...
update student
set istoric = istoric multiset union all bure(42, 23)
where id = 1
... 除了您现在使用的是 VARRAY(而不是嵌套的 table,您曾使用 in your previous question)。所以你得到一个错误信息:
ORA-00932: inconsistent datatypes: expected UDT got BURE
原因是,according to the documentation:
"While nested tables can also be changed in a piecewise fashions, varrays cannot....However, you cannot update or delete individual varray elements directly with SQL; you have to select the varray from the table, change it in PL/SQL, then update the table to include the new varray." (emphasis mine)
这是因为 VARRAY 是有序集,而嵌套表不是。除非有维护元素顺序的明确要求,否则最好使用嵌套表而不是 Varray:它们只是更方便。
下面是使用 PL/SQL 更新 Varray 的方法:
declare
lv bure;
cnt pls_integer;
begin
select istoric into lv
from student
where id = 1;
cnt := lv.count();
lv.extend();
lv(cnt+1) := 23 ;
lv.extend();
lv(cnt+2) := 69 ;
update student
set istoric = lv
where id = 1;
end;
/