An anonymous PL/SQL procedure to demonstrate the elementary use of PL/SQL tables : Table of rowtype « Collections « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » Collections » Table of rowtype 
26. 25. 1. An anonymous PL/SQL procedure to demonstrate the elementary use of PL/SQL tables
SQL>
SQL>
SQL>
SQL> create table employee (
  2  id                             number                         not null,
  3  employee_type_id                 number                         not null,
  4  external_id                    varchar2(30)                   not null,
  5  first_name                     varchar2(30)                   not null,
  6  middle_name                    varchar2(30),
  7  last_name                      varchar2(30)                   not null,
  8  name                           varchar2(100)                  not null,
  9  birth_date                     date                           not null,
 10  gender_id                      number                         not null );

Table created.

SQL>
SQL>
SQL>
SQL> declare
  2  TYPE name_table IS TABLE OF employee%ROWTYPE
  3  INDEX BY BINARY_INTEGER;
  4
  5  t_name                                name_table;
  6
  7  n_name                                binary_integer;
  8
  9  begin
 10    t_name(1).name  := 'AAA';
 11    t_name(10).name := 'BBB';
 12
 13    dbms_output.put_line(t_name(1).name);
 14    dbms_output.put_line(t_name(10).name);
 15
 16    dbms_output.put_line('There are '||t_name.count()||' elements.');
 17    n_name := t_name.first();
 18
 19    dbms_output.put_line('The first element is '||n_name||'.');
 20    n_name := t_name.next(n_name);
 21
 22    dbms_output.put_line('The next element is '||n_name||'.');
 23    n_name := t_name.last();
 24
 25    dbms_output.put_line('The last element is '||n_name||'.');
 26    n_name := t_name.prior(n_name);
 27
 28    dbms_output.put_line('The prior element is '||n_name||'.');
 29    if t_name.exists(1then
 30      dbms_output.put_line('Element exists.');
 31    end if;
 32
 33    dbms_output.put_line('I''m deleting element 10');
 34
 35    t_name.delete(10);
 36
 37    dbms_output.put_line('There are '||t_name.count()||' elements.');
 38
 39    if not t_name.exists(10then
 40      dbms_output.put_line('Element 10 no longer exists.');
 41    end if;
 42
 43    dbms_output.put_line('There are '||t_name.count()||' elements.');
 44
 45    dbms_output.put_line('I''m deleting all elements');
 46
 47    t_name.delete();
 48
 49    dbms_output.put_line('There are '||t_name.count()||' elements.');
 50  end;
 51  /
AAA
BBB
There are elements.
The first element is 1.
The next element is 10.
The last element is 10.
The prior element is 1.
Element exists.
I'm deleting element 10
There are elements.
Element 10 no longer exists.
There are elements.
I'm deleting all elements
There are elements.

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> drop table employee;

Table dropped.

SQL>
26. 25. Table of rowtype
26. 25. 1. An anonymous PL/SQL procedure to demonstrate the elementary use of PL/SQL tables
26. 25. 2. fetch bulk collect to table of rowtype
26. 25. 3. table of rowtype indexed by integer
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.