Map and order methods, PL-SQL Programming

Assignment Help:

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.


Related Discussions:- Map and order methods

Join query, Using a join on 3 tables, select 5 columns and 10 rows from the...

Using a join on 3 tables, select 5 columns and 10 rows from the 3 tables without the use of a Cartesian product Query: SELECT E.LAST_NAME, E.FIRST_NAME, S.BUILDING, S.BRAN

Components of an object type in pl/sql, Components of an Object Type: A...

Components of an Object Type: An object type encapsulates the operations and data. Therefore, you can declare the methods and attributes in an object type specification, but no

Row operators - sql operators, Row Operators The Row operators return ...

Row Operators The Row operators return or reference the particular rows. ALL retains the duplicate rows in the result of a query or in an aggregate expression. The DISTINCT el

Semidifference via not in and a subquery , Semidifference via NOT IN and a ...

Semidifference via NOT IN and a subquery SELECT StudentId FROM IS_CALLED WHERE Name = 'Devinder' AND StudentId NOT IN (SELECT StudentId FROM IS_ENROLLED_ON WHER

Parameter and keyword description - exit statement, Parameter and Keyword D...

Parameter and Keyword Description: EXIT: An unconditional EXIT statement (i.e., one without a WHEN clause) exits the present loop instantly. The Execution resumes with th

Assignments in pl/sql, Assignments in pl/sql The Variables and constants...

Assignments in pl/sql The Variables and constants are initialized every time a block or subprogram is entered. By default, the variables are initialized to NULL. Therefore, unle

produce vertical output format- oracle, Create a Oracle procedure to produ...

Create a Oracle procedure to produce vertical output format when selecting rows from a database table.

Python function, This task involves developing some functions that extract ...

This task involves developing some functions that extract data from an SQL database. The scenario is that a company which owns an online vehicle search website wants to generate so

Write a pl-sql program using the implicit cursor, Question: a) Given th...

Question: a) Given the following relation: Location(loc_id, bldg_code, room, capacity) The underlined field is a primary key. (i) Write a PL/SQL program using the impl

Build a purchases report that matches the general ledger, Great Plains (Mic...

Great Plains (Microsoft Dynamics) Purchases Report Project Description: I want to build a purchases report that matches the General Ledger. presently, when I join the PM20

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd