Compare user-defined type : Comparable « 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 » Comparable 
Compare user-defined type
 
SQL>
SQL> create or replace
  2  type person as object(
  3   first_name varchar2(100),
  4   last_name varchar2(100) )
  5  /

Type created.

SQL>
SQL> alter type person
  2  add attribute dob date
  3  cascade not including table data
  4  /

Type altered.

SQL>
SQL> create or replace
  2  type employee as object(
  3   name person,
  4   empno number,
  5   hiredate date,
  6   sal number,
  7   commission number,
  8   order member function match p_employee employee return integer )
  9  /

Type created.

SQL>
SQL> create or replace
  2  type body employee as
  3   order member function match p_employee employee return integer is
  4   begin
  5    if self.empno > p_employee.empno then
  6      return 1;
  7    elsif self.empno < p_employee.empno then
  8      return -1;
  9    else
 10      return 0;
 11    end if;
 12   end;
 13  end;
 14  /

Type body created.

SQL>
SQL>
SQL> declare
  2   emp1 employee;
  3   emp2 employee;
  4  begin
  5   emp1 := employeenull, 12345'01-JAN-01', 100100 );
  6   emp2 := employeenull, 67890'01-JAN-01', 100100 );
  7   if emp1 > emp2 then
  8     dbms_output.put_line'Employee is greater' );
  9   end if;
 10   if emp1 < emp2 then
 11     dbms_output.put_line'Employee is greater' );
 12   end if;
 13   if emp1 = emp2 then
 14     dbms_output.put_line'Employees are equal' );
 15   end if;
 16  end;
 17  /

PL/SQL procedure successfully completed.

SQL>
SQL> drop type employee;

Type dropped.

SQL>
SQL> drop type person;

Type dropped.

SQL>
SQL>

 
Related examples in the same category
1. Raise error in object memthod
2. Create user type with order
3. Define "Compare" method and use it in order by clause
4. Compare the appartment objects and display the results
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.