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
Project Description: I want somebody who can help me with an idea that I have been working on for a few months now. The person will require extensive knowledge of warcraft 3 PvP

3CX PBX sync Windows Service Project Description: !! You require access to a commercial version of the 3CX PBX system in order to be able to program the API !! !! You requ

Problem: (a) Define the following terms: (i) data mining. (ii) OLAP. (b) Differentiate between snowflake schema and star schema. Support your answer with appropriate

Develop Data Business Intelligence Project Project Description: We are linking our Microsoft SQL Database to GoodData Business Intelligence. We are seeking somebody who has e

Pl/SQL Expressions The Expressions are constructed by using the operands and operators. An operand is a constant, literal, variable, or function call which contributes a value

MILLER-UREY' S EXPERIMENTAL PROCEDURES - They recreated the probable conditions on the primitive earth in the laboratory. An atmosphere containing hydrogen, ammonia, me

Data Types in SQL - Decimal DECIMAL, NUMERIC, REAL, FLOAT and various other terms for various sets of rational numbers. When these key words are specified for the declared typ

Using Operator REF: You can retrieve refs by using the operator REF that, like VALUE, takes as its argument a correlation variable. In the illustration below, you retrieve one

Effects of NULL Operator As a general rule-but not a universal one-if NULL is an argument to an invocation of a system-defined read-only operator, then NULL is the result of t

Using RENAME in combination with JOIN - SQL Example gives pairs of ids of students having the same name, by joining two renamings of IS_CALLED. Example gives an equivalent ex