This script demonstrates the order method. : Object Method « Object Oriented Database « Oracle PL / SQL






This script demonstrates the order method.

   

SQL> CREATE OR REPLACE TYPE book_obj AS OBJECT (
  2     isbn        CHAR (10),
  3     title       VARCHAR2 (100),
  4     num_pages   NUMBER,
  5     ORDER MEMBER FUNCTION compare_book (p_isbn IN BOOK_OBJ)
  6        RETURN NUMBER
  7  );
  8  /

Type created.

SQL>
SQL> CREATE OR REPLACE TYPE BODY book_obj
  2  AS
  3     ORDER MEMBER FUNCTION compare_book (p_isbn IN BOOK_OBJ)
  4        RETURN NUMBER
  5     IS
  6     BEGIN
  7        IF p_isbn.isbn < SELF.isbn
  8        THEN
  9           RETURN 1;
 10        ELSIF p_isbn.isbn > SELF.isbn
 11        THEN
 12           RETURN -1;
 13        ELSE
 14           RETURN 0;
 15        END IF;
 16     END compare_book;
 17  END;
 18  /

Type body created.

SQL>

   
    
    
  








Related examples in the same category

1.Creating User-defined Functions for Column Objects
2.Use method from object in select command
3.Access member variable in member function in a type
4.Compare two type object instances
5.A sample object type with a MAP member function
6.A sample object type with an ORDER member function.
7.This script builds a sample object type with member variables and functions
8.This script demonstrates the static method.
9.Type with member procedure
10.Demonstrates the member method.