Oracle Map Member

PL/SQL MAP Member Functions

pl/sql_map_member_functions

The MAP member functions are used for performing comparisons between a single attribute of an object instance to a single attribute of another object instance.

The MAP functions do not accept any formal parameters and must return a scalar data type, either CHAR, VARCHAR2, NUMBER or DATE, which can be easily compared by the system. The MAP member functions are used for validating object instances with a single attribute.

Note -The MAP functions cannot be implemented on Static functions, but Member functions only.

CREATE OR REPLACE TYPE obj_map AS OBJECT
(
obj_var1 NUMBER,
MEMBER PROCEDURE print,
MAP MEMBER FUNCTION func_map RETURN NUMBER
);

CREATE OR REPLACE TYPE BODY obj_map
IS
       MEMBER PROCEDURE print
       IS
       BEGIN
           dbms_output.put_line(self.obj_var1);
       END;
       MAP MEMBER FUNCTION func_map RETURN NUMBER
       IS
       BEGIN
           RETURN obj_var1;
       END;
END;

In the above snippet, an object is created with an attribute of the number data type, a member procedure for printing the attribute value of the current instance and an MAP member function returning the attribute of the current instance.

The attribute value for multiple instances can be compared with the help of the below anonymous block which has two instances of the object OBJ_MAP, which accepts bind values as their initialization parameter. In the execution section, the attribute values of the two instances of the objects are printed using the print procedure from the object.

The IF condition merely checks for the equality between the two object instances, which internally calls the MAP member function and compares the result of the two instance's MAP member function's return value, which is the attribute value of the two instances ideally. The result of the comparison between the two object instance's attributes is printed appropriately using the PUT_LINE procedure.

DECLARE
  l_obj_map1 obj_map:=obj_map(:l_obj_map1);
  l_obj_map2 obj_map:=obj_map(:l_obj_map2);
BEGIN
      l_obj_map1.print;
      l_obj_map2.print;
      IF l_obj_map1=l_obj_map2 THEN
          dbms_output.put_line('The two intances are equal');
      ELSE  
           dbms_output.put_line('The two intances are not equal');
      END IF;
END;

Result:

1. When l_obj_map1= 30 and l_obj_map2= 50 then,

30
50
The two intances are not equal

2. When l_obj_map1= 50 and l_obj_map2= 50 then,

50
50
The two intances are equal


If you like dEexams.com and would like to contribute, you can also write your article here or mail your article to admin@deexams.com . See your article appearing on the dEexams.com main page and help others to learn.


Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.


Python if , elif and else

Python Conditions and If statements

  • 0
Python for beginners

Learning Python Part 1

  • 3
Struct Alignment and Padding

Struct Alignment and Padding in C++ And C

  • 0
Friend function

Friend function C++

  • 0
Pointers

C++ Pointers

  • 0
Structures

C++ Structures

  • 0
Types of Inheritance in C++

Inheritance and access specifiers C++

  • 0
Java date pattern

Java Date Pattern Syntax

  • 0
Java Date and Calendar

Java Date formats

  • 0
JAVA Data Type

Data types in Java

  • 0
Java unreachable code

Unreachable Code Error in Java

  • 0

Post Comment

Comments(0)

WEB TECHNOLOGY

Articles

×

Forgot Password

Please enter your email address below and we will send you information to change your password.