Using explicit definition to define record types and a compound record type; and, the use of nested types : Record Data Type « 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 » Record Data Type 
Using explicit definition to define record types and a compound record type; and, the use of nested types
    
SQL> CREATE TABLE emp
  2   (emp_id              INTEGER             NOT NULL
  3   ,fname               VARCHAR2(30 CHAR)   NOT NULL
  4   ,mid_name           VARCHAR2(CHAR)
  5   ,lname                VARCHAR2(30 CHAR)   NOT NULL
  6   ,CONSTRAINT emp_pk PRIMARY KEY (emp_id));

Table created.

SQL>
SQL>
SQL> CREATE TABLE customer (
  2     id         NUMBER PRIMARY KEY,
  3     fname VARCHAR2(50),
  4     lname  VARCHAR2(50)
  5   );

Table created.

SQL>
SQL>
SQL>
SQL>
SQL> INSERT INTO customer (id, fname, lname)VALUES (1'A''B');

row created.

SQL>
SQL>
SQL>
SQL> INSERT INTO customer (id, fname, lname)VALUES (2'C''D');

row created.

SQL>
SQL>
SQL>
SQL> INSERT INTO customer (id, fname, lname)VALUES (3'Enn', 'F');

row created.

SQL>
SQL>
SQL>
SQL> INSERT INTO customer (id, fname, lname)VALUES (4'G''H');

row created.

SQL>
SQL>
SQL>
SQL> INSERT INTO customer (id, fname, lname)VALUES (5'G''Z');

row created.

SQL>
SQL>
SQL>
SQL>
SQL> SET ECHO ON
SQL>
SQL> 
SQL> DECLARE
  2     TYPE emp_record IS RECORD(emp_id INTEGER,fname VARCHAR2(30 CHAR),mid_name VARCHAR2(CHAR),lname VARCHAR2(30 CHAR));
  3
  4     TYPE address_record IS RECORD(address_id INTEGER,emp_id INTEGER,address1 VARCHAR2(30 CHAR),address2 VARCHAR2(30 CHAR)
  5     ,address3 VARCHAR2(30 CHAR),city VARCHAR2(20 CHAR),state VARCHAR2(20 CHAR),postal_code VARCHAR2(20 CHAR),country_code VARCHAR2(10 CHAR));
  6
  7     
  8     TYPE empType IS RECORD(emp emp_RECORD,address ADDRESS_RECORD);
  9
 10     
 11     anEmp empType;
 12
 13   BEGIN
 14
 15     
 16     anEmp.emp.emp_id := 3;
 17     anEmp.emp.fname := 'U';
 18     anEmp.emp.mid_name := 'S';
 19     anEmp.emp.lname := 'G';
 20
 21     
 22     anEmp.address.address_id := 1;
 23     anEmp.address.emp_id := 3;
 24     anEmp.address.address1 := 'R';
 25     anEmp.address.address2 := '';
 26     anEmp.address.address3 := '';
 27     anEmp.address.city := 'City';
 28     anEmp.address.state := 'NY';
 29     anEmp.address.postal_code := '10027-1111';
 30     anEmp.address.country_code := 'USA';
 31     
 32     INSERT INTO emp VALUES(anEmp.emp.emp_id,anEmp.emp.fname,anEmp.emp.mid_name,anEmp.emp.lname);
 33
 34     
 35     COMMIT;
 36
 37   END;
 38   /

PL/SQL procedure successfully completed.

SQL>
SQL> drop TABLE emp;

Table dropped.

SQL> drop table customer;

Table dropped.

SQL>

   
    
    
    
  
Related examples in the same category
1. PL/SQL Collections: record type
2. The %ROWTYPE can also be used to create a record based on the structure of a cursor
3. A simple record that holds a person's name, phone number, and birth date and fill data in
4. Declare the record data type
5. Load a row in table to record type
6. A record is populated using a SELECT statement
7. declare record with not null attribute
8. Assign a wrong record type
9. This block shows legal and illegal record assignments.
10. How to select into a record.
11. Select into Records
12. Record type
13. Nest records, access the names of the nested records by using another component selector, or period
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.