Demonstrates the member method. : Object Method « Object Oriented Database « Oracle PL / SQL






Demonstrates the member method.

    
SQL>
SQL>
SQL> CREATE OR REPLACE TYPE BookType AS OBJECT (
  2     rebate   NUMBER (10, 4),
  3     price           NUMBER (10, 2),
  4     MEMBER FUNCTION discount_price
  5        RETURN NUMBER
  6  )
  7  INSTANTIABLE FINAL;
  8  /

Type created.

SQL>
SQL> CREATE OR REPLACE TYPE BODY BookType
  2  AS
  3     MEMBER FUNCTION discount_price
  4        RETURN NUMBER
  5     IS
  6     BEGIN
  7        RETURN (SELF.price * (1 - SELF.rebate));
  8     END discount_price;
  9  END;
 10  /

Type body created.

SQL>
SQL>  SET SERVEROUTPUT ON SIZE 1000000
SQL>
SQL>  DECLARE
  2      v_price BookType := BookType(.1, 75.00);
  3   BEGIN
  4      dbms_output.put_line(v_price.discount_price);
  5   END;
  6   /
67.5

PL/SQL procedure successfully completed.

SQL>

   
    
    
    
  








Related examples in the same category

1.Creating User-defined Functions for Column Objects
2.Use method from object in select command
3.Access member variable in member function in a type
4.Compare two type object instances
5.A sample object type with a MAP member function
6.A sample object type with an ORDER member function.
7.This script builds a sample object type with member variables and functions
8.This script demonstrates the static method.
9.This script demonstrates the order method.
10.Type with member procedure