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