Using ORDER method:
An ORDER method is used to compare the object values and return values like as 1 denotes in which the current object is greater than the parameter, 0 denotes equality and -1 if the current object is less than the argument.
Note: When Member Functions are used their requirement to be specified a Restrict_References require to be specified.
Either an MAP or ORDER function alone needs to be specified.
The Object Types holds 2 parts like packages namely Specification and Body. A body is a must only when any member function is specified.
If an object type is established without any member function comparison cannot be performed as the following instance described:
select empno,ename,a.sal from emptab a;
EMPNO ENAME
--------- --------------------
SAL(BASIC, DA)
------------------------------
1 hema
SALTYPE(1000, 2300)
2 magesh
SALTYPE(10000, 20000
select a.empno,a.ename,a.sal from emptab a, emptab b
where a.sal >=b.sal;
where a.sal >=b.sal
*
ERROR at line 2:
ORA-22950: cannot ORDER objects without ORDER or MAP method Additionally to do this operation write a function known as compare that compares the two objects.
CREATE OR REPLACE TYPE dep_type AS Object
(deptno number,dname varchar2(20)
Order Member Function compare (dtype In dep_type) Return Number);
Create or replace type body dep_type as order member function compare (dtype in dep_type) return number is if self.deptno > dtype.deptno then it will return 1;
else
end if;
end;
return 0;
This permits the above query to be executed.