Map and order methods, PL-SQL Programming

Map and Order Methods:

The values of the scalar datatype like CHAR or REAL have a predefined order that allows them to be compared. While, the instances of an object type has no predefined order. To put them in order, the PL/SQL calls a map method supplied by you.

In the illustration below, the keyword MAP indicates that the method converts orders rational objects by mapping them to the REAL values:

CREATE TYPE Rational AS OBJECT (

num INTEGER,

den INTEGER,

MAP MEMBER FUNCTION convert RETURN REAL,

...

);

CREATE TYPE BODY Rational AS

MAP MEMBER FUNCTION convert RETURN REAL IS

BEGIN

RETURN num / den;

END convert;

...

END;

The PL/SQL uses the ordering to compute the Boolean expressions like x > y, and to do comparisons implied by the GROUP BY, DISTINCT, and ORDER BY clauses. The Map method convert returns to the relative position of an object in the ordering of all the rational objects.

An object type can have only one map method that should be a parameter less function with one of the scalar return types shown below: DATE, VARCHAR2, NUMBER, or an ANSI SQL type like CHARACTER or REAL.

On the other hand, you can supply the PL/SQL with an order method. An object type can have only one order method that should be a function which returns a numeric result. In the illustration below, the keyword ORDER indicates that method match compares 2 objects:

CREATE TYPE Customer AS OBJECT (

id NUMBER,

name VARCHAR2(20),

addr VARCHAR2(30),

ORDER MEMBER FUNCTION match (c Customer) RETURN INTEGER

);

CREATE TYPE BODY Customer AS

ORDER MEMBER FUNCTION match (c Customer) RETURN INTEGER IS

BEGIN

IF id < c.id THEN

RETURN -1; -- any negative number will do

ELSIF id > c.id THEN

RETURN 1; -- any positive number will do

ELSE

RETURN 0;

END IF;

END;

END;

Every order method takes merely two parameters: the built-in parameter SELF & the other object of similar type. If c1 and c2 are Customer objects, a comparison like c1 > c2 calls method match automatically. The method returns a , zero, negative number or a positive number suggesting that the SELF is correspondingly less than, equal to, or greater than the other parameter. If whichever parameter passed to an order method is null, then the method returns a null.

Posted Date: 10/6/2012 8:09:45 AM | Location : United States







Related Discussions:- Map and order methods, Assignment Help, Ask Question on Map and order methods, Get Answer, Expert's Help, Map and order methods Discussions

Write discussion on Map and order methods
Your posts are moderated
Related Questions
%TYPE Attribute The %TYPE attribute gives the datatype of a record, field, nested table, database column, or the variable. You can use the %TYPE attribute as the datatype speci

Demonstrate your knowledge of PL/SQL programming by writing and thoroughly testing triggers and stored procedures associated with an e-commerce application that provides security l

Avoid the NOT NULL Constraint In the PL/SQL, using the NOT NULL constraint incur a performance cost. Consider the illustration as shown below: PROCEDURE calc_m IS m NUMB

THEO R Y OF PANSPERMIA - Arrhenius (1908) postulated the cosmic panspermia theory that claims that organisms existed throughout the universe, and their spores, etc., could

Project Description: I want to write some SQL statements. The things I need are between pages 5-7. The only problem is that i want it till tomorrow. Skills required is SQL

Brewbean's is implementing a new discount for return shoppers - every fifth completed order receives a 10% discount. The count of orders for a shopper is placed in a packaged varia

Cursor Variables Similar to a cursor, cursor variable points to the current row in the result set of a multi-row query. But, dissimilar a cursor, a cursor variable can be opene

Selecting Objects: Suppose that you have run the SQL*Plus script below that creates object type Person and object table persons, and that you have settled the table: CREATE

Using PRIOR and NEXT The PRIOR(n) returns the index number that precede index n in a collection. The NEXT(n) returns the index number which succeed the index n. If n has no pr

Character Types The Character types allow you to store alphanumeric data, represent words and text, and manipulate the character strings. CHAR You use the CHAR dataty