PL/SQL Collections (Nested Tables)
来源:互联网 发布:苹果手机屏幕修复软件 编辑:程序博客网 时间:2024/06/05 18:38
What Is a Collection?
A collection is an ordered group of elements, all of the same type. It is a general concept that encompasses lists, arrays, and other familiar datatypes. Each element has a unique subscript that determines its position in the collection.
Understanding Nested Tables
Within the database, nested tables can be considered one-column database tables. Oracle stores the rows of a nested table in no particular order. But, when you retrieve the nested table into a PL/SQL variable, the rows are given consecutive subscripts starting at 1. That gives you array-like access to individual rows.
PL/SQL nested tables are like one-dimensional arrays. You can model multi-dimensional arrays by creating nested tables whose elements are also nested tables.
Define a Collection of Nested Tables
For nested tables, use the syntax:TYPEtype_name
IS TABLE OFelement_type
[NOT NULL];
type_name
is a type specifier used later to declare collections. For nested tables declared within PL/SQL,element_type
is any PL/SQL datatype except:
Initializing and Referencing Collections
Until you initialize it, a nested table or varray is atomically null: the collection itself is null, not its elements. To initialize a nested table or varray, you use aconstructor, a system-defined function with the same name as the collection type. This function "constructs" collections from the elements passed to it.
You must explicitly call a constructor for each varray and nested table variable. (Associative arrays, the third kind of collection, do not use constructors.) Constructor calls are allowed wherever function calls are allowed.
Example: Constructor for a Nested Table
In the following example, you pass multiple elements to the constructorCourseList()
, which returns a nested table containing those elements:
DECLARE TYPE CourseList IS TABLE OF VARCHAR2(16); my_courses CourseList;BEGIN my_courses := CourseList('Econ 2010', 'Acct 3401', 'Mgmt 3100');END;
Example
DECLARE TYPE table_varchar IS TABLE OF VARCHAR2 (30); old_table_varchar table_varchar; new_table_varchar table_varchar;BEGIN old_table_varchar := table_varchar ('AA', 'BB'); new_table_varchar := table_varchar ('CC', 'DD'); FOR i IN old_table_varchar.FIRST .. old_table_varchar.LAST LOOP DBMS_OUTPUT.put_line (old_table_varchar (i) || '-' || new_table_varchar (i)); UPDATE TEMP00 SET COL01 = new_table_varchar (i) WHERE COL01 = old_table_varchar (i); END LOOP;EXCEPTION WHEN OTHERS THEN ROLLBACK; DBMS_OUTPUT.put_line (SQLCODE || ':' || SQLERRM);END;/
参考:http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm
参考:http://www.adp-gmbh.ch/ora/plsql/coll/constructor.html
- PL/SQL Collections (Nested Tables)
- oracle pl/sql Nested Table
- PL/SQL Collections and Records
- PL/SQL Collections and Records
- PL/SQL 中的nested loop code
- PL/SQL中的集合类型(Collections in PL/SQL)
- Filling nested internal tables
- Oracle PL/SQL之嵌套表(Nested Table)
- 学习笔记:关于PL/SQL 集合类型record、pl/sql表、varray、nested table
- PL/SQL Developer 报错Dynamic Performance Tables not access
- PL SQL 查询时 dynamic performance tables not accessible 错误
- pl/sql Dynamic Performance Tables not accessible 问题解决办法
- PL/SQL Developer报错Dynamic Performance Tables not accessible
- PL/SQL Developer报错Dynamic Performance Tables not accessible
- PL/SQL Developer Error - Dynamic Performance Tables not accessible
- PL/SQL Developer报错Dynamic Performance Tables not accessible
- PL/SQL补疑之Collections and Records
- 利用PL/SQL的nested table和bulk collect into方法提高性能
- hibernate generator class="" 详解
- SCTP编程
- hdu 3826 Squarefree number
- 动易调用.net控件问题
- 关于sprintf的一些东西(在stdio.h里)
- PL/SQL Collections (Nested Tables)
- 爱的诠释,你懂的!我们都懂的!
- 服务器程序和数据库的定期备份,删除,传输到其他服务器上
- 工
- Vmare player
- StringUtils全览
- 将tomcat设为开机自动在后台运行
- 获取日期对应的财务期间
- java调用webservice获取指定城市天气情况的例子