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

Creating a sql file, Creating a SQL file 1. Open a new file in Notepad...

Creating a SQL file 1. Open a new file in Notepad++ and save it to the location c:\mysql\bin, with the name lab8script.sql (the file extension should be .sql ). Add a MySQL co

Use tsql function sql server 2012, I want someone to write a TSQL function ...

I want someone to write a TSQL function that returns the name of the ODBC DSN. I will use the queries below, to get information about the connection, but none of these return th

Cursor variables in pl sql, Cursor Variables:   To execute the multi-...

Cursor Variables:   To execute the multi-row query, the Oracle opens an unnamed work region that stores the processing information. You can use an explicit cursor that names

Keyword & parameter description - exception_init pragma, Keyword & Paramete...

Keyword & Parameter Description: PRAGMA: These keywords signify that the statement is a pragma (i.e. compiler directive). The Pragmas are processed at the compile time, n

Operators on tables and rows, Operators on Tables and Rows Row Extrac...

Operators on Tables and Rows Row Extraction TUPLE FROM r, SQL has row subqueries. These are just like scalar subqueries except that they may specify more than one column.

Goto statement - sequential control, GOTO Statement The GOTO statement b...

GOTO Statement The GOTO statement branches to a label unconditionally. The label must be exclusive within its scope and should precede an executable statement or a PL/SQL block.

Procedure, 1. Create a procedure called TAX_COST_SP to accomplish the tax c...

1. Create a procedure called TAX_COST_SP to accomplish the tax calculation task. Keep in mind that the state and subtotal values are inputs into the procedure and the procedure is

Using rename in combination with join - sql, Using RENAME in combination wi...

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

Select query, Query: SELECT * FROM EMPLOYEE1; Select 5 columns and ...

Query: SELECT * FROM EMPLOYEE1; Select 5 columns and all rows from one table Query: SELECT C_ID, COMPANY, BUILDING, DEPARTMENT, BRANCH FROM CONTRACT;

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

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