Use type member function in select statement : Select « Object Oriented Database « 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 » Object Oriented Database » Select 
Use type member function in select statement
 
SQL>
SQL>
SQL> create or replace
  2  type person as object (
  3   first_name varchar2(100),
  4   last_name varchar2(100),
  5   dob date,
  6   phone varchar2(100),
  7   member function get_last_name return varchar2,
  8   member function get_phone_number return varchar2 )
  9  not final
 10  /

Type created.

SQL>
SQL>
SQL> create or replace
  2  type body person as
  3    member function get_last_name return varchar2 is
  4    begin
  5      return self.last_name;
  6    end;
  7    member function get_phone_number return varchar2 is
  8    begin
  9      return self.phone;
 10    end;
 11  end;
 12  /

Type body created.

SQL>
SQL> create table person_tablep person );

Table created.

SQL>
SQL>
SQL>
SQL> create or replace
  2  type new_employee under person (
  3    empno number,
  4    hiredate date,
  5    work_phone varchar2(100),
  6    overriding member function get_phone_number return varchar2,
  7    member function get_home_phone_number return varchar2 )
  8  not final
  9  /

Type created.

SQL>
SQL> create or replace
  2  type body new_employee as
  3    overriding member function get_phone_number return varchar2 is
  4    begin
  5      return self.work_phone;
  6    end;
  7    member function get_home_phone_number return varchar2 is
  8    begin
  9      return self.phone;
 10    end;
 11  end;
 12  /

Type body created.

SQL>
SQL>
SQL>  select x.p.get_last_name() last_name,
  2           x.p.phone phone,
  3           treatx.p as new_employee ).work_phone work_phone,
  4           x.p.get_phone_number() "GET_PHONE_NUMBER()",
  5           treatx.p as new_employee ).get_phone_number() treat_as_new_employee
  6      from person_table x
  7    /

no rows selected

SQL>
SQL> drop table person_table;

Table dropped.

SQL>
SQL> drop type new_employee;

Type dropped.

SQL>
SQL> drop type person;

Type dropped.

SQL>

 
Related examples in the same category
1. Display the New Table (SELECT * and SELECT by Column Name)
2. Query object table
3. SELECT Only One Column in the Composite
4. SELECT with a WHERE Clause
5. Query data from table based on object
6. SELECTing Individual Columns in TCROs
7. Use the function we created: use the table alias in our SELECT as well as the qualifier
8. Use * to reference column with user-defined type
9. demonstrates SQL operations on object types.
10. Select the object type from the table, rather than the columns.
11. Use %ROWTYPE to select from the relational table.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.