constructormethod.sql

来自「介绍Oracle PL SQL编程」· SQL 代码 · 共 47 行

SQL
47
字号
/*
 * ConstructorMethod.sql
 * Chapter 14, Oracle10g PL/SQL Programming
 * by Ron Hardman, Mike McLaughlin, Scott Urman
 *
 * This script demonstrates the user-defined constructor method.
 */

exec clean_schema.synonyms
exec clean_schema.tables
exec clean_schema.objects

CREATE OR REPLACE TYPE discount_price_obj AS OBJECT (
   discount_rate   NUMBER (10, 4),
   price           NUMBER (10, 2),
   CONSTRUCTOR FUNCTION discount_price_obj (price NUMBER)
      RETURN SELF AS RESULT
)
INSTANTIABLE FINAL;
/

CREATE OR REPLACE TYPE BODY discount_price_obj
AS
   CONSTRUCTOR FUNCTION discount_price_obj (price NUMBER)
      RETURN SELF AS RESULT
   AS
   BEGIN
      SELF.price := price * .9;
      RETURN;
   END discount_price_obj;
END;
/

/******************************************
* Run the following to test: 
*      constructorMethod.sql
*
* SET SERVEROUTPUT ON SIZE 1000000
* DECLARE
*    v_price   discount_price_obj := discount_price_obj (75);
* BEGIN
*    DBMS_OUTPUT.put_line (v_price.price);
* END;
* /
* 
*******************************************/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?