Storing and retreiving a nested table with non-sequential keys : Table of Date « PL SQL « Oracle PL / SQL

Oracle PL / SQL
1. Aggregate Functions
2. Analytical Functions
3. Char Functions
4. Constraints
5. Conversion Functions
6. Cursor
7. Data Type
8. Date Timezone
9. Hierarchical Query
10. Index
11. Insert Delete Update
12. Large Objects
13. Numeric Math Functions
14. Object Oriented Database
15. PL SQL
16. Regular Expressions
17. Report Column Page
18. Result Set
19. Select Query
20. Sequence
21. SQL Plus
22. Stored Procedure Function
23. Subquery
24. System Packages
25. System Tables Views
26. Table
27. Table Joins
28. Trigger
29. User Previliege
30. View
31. XML
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 Tutorial
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 » PL SQL » Table of Date 
Storing and retreiving a nested table with non-sequential keys
 
SQL>
SQL> CREATE OR REPLACE TYPE DateTab AS
  2    TABLE OF DATE;
  3  /

Type created.

SQL> CREATE TABLE MyDate (
  2    key        VARCHAR2(100PRIMARY KEY,
  3    date_list  DateTab)
  4    NESTED TABLE date_list STORE AS dates_tab;

Table created.

SQL>
SQL> create or replace PROCEDURE Print(p_Dates IN DateTabIS
  2      v_Index BINARY_INTEGER := p_Dates.FIRST;
  3  BEGIN
  4      WHILE v_Index <= p_Dates.LAST LOOP
  5        DBMS_OUTPUT.PUT('  ' || v_Index || ': ');
  6        DBMS_OUTPUT.PUT_LINE(TO_CHAR(p_Dates(v_Index)'DD-MON-YYYY'));
  7        v_Index := p_Dates.NEXT(v_Index);
  8      END LOOP;
  9  END Print;
 10  /

Procedure created.

SQL> show error
No errors.
SQL>
SQL> DECLARE
  2    v_Dates DateTab := DateTab(TO_DATE('04-JUL-1776', 'DD-MON-YYYY'),
  3                               TO_DATE('12-APR-1861', 'DD-MON-YYYY'),
  4                               TO_DATE('05-JUN-1968', 'DD-MON-YYYY'),
  5                               TO_DATE('26-JAN-1986', 'DD-MON-YYYY'),
  6                               TO_DATE('01-JAN-2001', 'DD-MON-YYYY'));
  7
  8  BEGIN
  9    v_Dates.DELETE(2);
 10
 11    DBMS_OUTPUT.PUT_LINE('Initial value of the table:');
 12    Print(v_Dates);
 13
 14    INSERT INTO MyDate (key, date_listVALUES ('Dates in American History', v_Dates);
 15
 16    SELECT date_list INTO v_Dates FROM MyDate WHERE key = 'Dates in American History';
 17
 18    DBMS_OUTPUT.PUT_LINE('Table after INSERT and SELECT:');
 19    Print(v_Dates);
 20  END;
 21  /
Initial value of the table:
104-JUL-1776
305-JUN-1968
426-JAN-1986
501-JAN-2001
Table after INSERT and SELECT:
104-JUL-1776
205-JUN-1968
326-JAN-1986
401-JAN-2001

PL/SQL procedure successfully completed.

SQL>
SQL> drop table MyDate;

Table dropped.

SQL>
SQL>
SQL>

 
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.