Oracle 11g Release 1 (11.1) PL/SQL_多维 Collection 类型和其异常,虽然 collection 只有一维的,但可以模型一个多维的。创建一
本文内容
多维 Collection
虽然 collection 只有一维的,但可以模型一个多维的。创建一个 collection,其每个元素也是 collection 。例如,,创建一个 varray 的 nested table,一个 varray 的 varray,一个 nested table 的 varray 等。
示例1:演示多维 varray
declare type t1 is varray(10) of integer; type nt1 is varray(10) of t1; — multilevel varray type va t1 := t1(2,3,5); — initialize multilevel varray nva nt1 := nt1(va, t1(55,6,73), t1(2,4), va); i integer; va1 t1;begin — multilevel access i := nva(2)(3); — i will get value 73 dbms_output.put_line(‘i = ‘ || i); — add a new varray element to nva nva.extend; — replace inner varray elements nva(5) := t1(56, 32); nva(4) := t1(45,43,67,43345); — replace an inner integer element nva(4)(4) := 1; — replaces 43345 with 1 — add a new element to the 4th varray element — and store integer 89 into it. nva(4).extend; nva(4)(5) := 89;end;/
示例2:演示多维 nested table
VARCHAR2(20); TYPE Ntb1 tb1; tv1; — table of varray elements vtb1 tb1 := tb1(‘one’, ‘three’); vntb1 ntb1 := ntb1(vtb1); vntb2 ntb2 := ntb2(tv1(3,5), tv1(5,7,3)); — table of varray elementsBEGIN vntb1.EXTEND; vntb1(2) := vntb1(1); — delete the first element in vntb1 vntb1.DELETE(1); — delete the first string — from the second table in the nested table vntb1(2).DELETE(1);END;/
示例3:演示多维 associative array
PLS_INTEGER; tb1 va1 INDEX BY PLS_INTEGER; v1 va1 := va1(‘hello’, ‘world’); v2 ntb1; v3 ntb2; v4 tb1; v5 tb1; — empty tableBEGIN v4(1) := 34; v4(2) := 46456; v4(456) := 343; v2(23) := v4; v3(34) := va1(33, 456, 656, 343); — assign an empty table to v2(35) and try again v2(35) := v5; v2(35)(2) := 78; — it works nowEND;/
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/1926346.html