Query a stored varray. : varray « 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL / SQL » PL SQL » varray 
Query a stored varray.
 
SQL>
SQL> CREATE OR REPLACE TYPE BookList AS VARRAY(10OF NUMBER(4);
  2  /

Type created.

SQL>
SQL>
SQL> CREATE TABLE class_material (
  2    department       CHAR(3),
  3    course           NUMBER(3),
  4    required_reading BookList
  5  );

Table created.

SQL>
SQL> CREATE TABLE books (
  2    catalog_number NUMBER(4)     PRIMARY KEY,
  3    title          VARCHAR2(40),
  4    author1        VARCHAR2(40),
  5    author2        VARCHAR2(40),
  6    author3        VARCHAR2(40),
  7    author4        VARCHAR2(40)
  8  );

Table created.

SQL>
SQL> INSERT INTO books (catalog_number, title, author1)
  2             VALUES (1000'Oracle8i Advanced PL/SQL Programming', 'Urman, Scott');

row created.

SQL>
SQL> INSERT INTO books (catalog_number, title, author1, author2, author3)
  2             VALUES (1001'Oracle8i: A Beginner''s Guide', 'Abbey, Michael', 'Corey, Michael J.', 'Abramson, Ian');

row created.

SQL>
SQL> INSERT INTO books (catalog_number, title, author1, author2, author3, author4)
  2             VALUES (1002'Oracle8 Tuning', 'Corey, Michael J.', 'Abbey, Michael', 'Dechichio, Daniel J.', 'Abramson, Ian');

row created.

SQL>
SQL> INSERT INTO books (catalog_number, title, author1, author2)
  2             VALUES (2001'A History of the World', 'Arlington, Arlene', 'Verity, Victor');

row created.

SQL>
SQL> INSERT INTO books (catalog_number, title, author1)
  2             VALUES (3001'Bach and the Modern World', 'Foo, Fred');

row created.

SQL>
SQL> INSERT INTO books (catalog_number, title, author1)
  2             VALUES (3002'Introduction to the Piano', 'Morenson, Mary');

row created.

SQL> CREATE OR REPLACE PROCEDURE PrintRequired(
  2    p_Department IN class_material.department%TYPE,
  3    p_Course IN class_material.course%TYPEIS
  4
  5    v_Books class_material.required_reading%TYPE;
  6    v_Title books.title%TYPE;
  7  BEGIN
  8    SELECT required_reading
  9      INTO v_Books
 10      FROM class_material
 11      WHERE department = p_Department
 12      AND course = p_Course;
 13
 14    DBMS_OUTPUT.PUT('Required reading for ' || RTRIM(p_Department));
 15    DBMS_OUTPUT.PUT_LINE(' ' || p_Course || ':');
 16
 17    FOR v_Index IN 1..v_Books.COUNT LOOP
 18      SELECT title
 19        INTO v_Title
 20        FROM books
 21        WHERE catalog_number = v_Books(v_Index);
 22      DBMS_OUTPUT.PUT_LINE(
 23        '  ' || v_Books(v_Index|| ': ' || v_Title);
 24    END LOOP;
 25  END PrintRequired;
 26  /

Procedure created.

SQL>
SQL> DECLARE
  2    CURSOR c_Courses IS
  3      SELECT department, course
  4        FROM class_material
  5        ORDER BY department;
  6  BEGIN
  7    FOR v_Rec IN c_Courses LOOP
  8      PrintRequired(v_Rec.department, v_Rec.course);
  9    END LOOP;
 10  END;
 11  /

PL/SQL procedure successfully completed.

SQL>
SQL> drop table class_material;

Table dropped.

SQL>
SQL> drop table books;

Table dropped.

SQL>
SQL>

--Overloading packaged subprograms based on object types.

CREATE OR REPLACE TYPE t11 AS OBJECT (
  f NUMBER
)
/

CREATE OR REPLACE TYPE t21 AS OBJECT (
  f NUMBER
)
/

CREATE OR REPLACE PACKAGE Overload AS
  PROCEDURE Proc(p_Parameter1 IN t11);
  PROCEDURE Proc(p_Parameter1 IN t21);
END Overload;
/

CREATE OR REPLACE PACKAGE BODY Overload AS
  PROCEDURE Proc(p_Parameter1 IN t11IS
  BEGIN
    DBMS_OUTPUT.PUT_LINE('Proc(t11)' || p_Parameter1.f);
  END Proc;

  PROCEDURE Proc(p_Parameter1 IN t21IS
  BEGIN
    DBMS_OUTPUT.PUT_LINE('Proc(t21)' || p_Parameter1.f);
  END Proc;
END Overload;
/

set serveroutput on

DECLARE
  v_Obj1 t11 := t11(1);
  v_Obj2 t21 := t21(2);
BEGIN
  Overload.Proc(v_Obj1);
  Overload.Proc(v_Obj2);
END;
/

drop type t11;

drop type t21;

--

 
Related examples in the same category
1. Varray constructors.
2. legal and illegal varray assignments.
3. TYPE Strings IS VARRAY(5) OF VARCHAR2(10)
4. Create a varray based on user defined type
5. Store pre-defined constants in VARRAY
6. Creating and Using VARRAYs
7. VARRAY of VARCHAR2 and Varray of number
8. Table of numbers and varray of numbers
9. Initialize the array and create two entries using the constructor
10. Reference elements in varray
11. assignments to varray elements, and the ORA-6532 and ORA-6533 errors.
12. ORA-06533: Subscript beyond count
ww___w_.___j__a__v___a__2s.__c__o___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.