131.Oracle数据库SQL开发之 数据库对象——用户自定义的构造函数
欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/50087121
用户可以在PL/SQL中定义自己的构造函数,用于初始化一个新对象。
CREATETYPE t_person2 AS OBJECT (
id INTEGER,
first_nameVARCHAR2(10),
last_name VARCHAR2(10),
dob DATE,
phone VARCHAR2(12),
CONSTRUCTORFUNCTION t_person2(
p_id INTEGER,
p_first_name VARCHAR2,
p_last_name VARCHAR2
) RETURN SELFAS RESULT,
CONSTRUCTORFUNCTION t_person2(
p_id INTEGER,
p_first_name VARCHAR2,
p_last_name VARCHAR2,
p_dob DATE
) RETURN SELFAS RESULT
);
/
声明了两个构造函数的方法。
查看如下:
object_user2@PDB1> describe t_person2
Name Null? Type
------------------------------------------------------------- ------------------------------------
ID NUMBER(38)
FIRST_NAME VARCHAR2(10)
LAST_NAME VARCHAR2(10)
DOB DATE
PHONE VARCHAR2(12)
METHOD
------
FINAL CONSTRUCTOR FUNCTION T_PERSON2 RETURNSSELF AS RESULT
Argument Name Type In/Out Default?
----------------------------------------------------- ------ --------
P_ID NUMBER IN
P_FIRST_NAME VARCHAR2 IN
P_LAST_NAME VARCHAR2 IN
METHOD
------
FINAL CONSTRUCTOR FUNCTION T_PERSON2 RETURNSSELF AS RESULT
Argument Name Type In/Out Default?
------------------------------ ----------------------------- --------
P_ID NUMBER IN
P_FIRST_NAME VARCHAR2 IN
P_LAST_NAME VARCHAR2 IN
P_DOB DATE IN
查看如下:
object_user2@PDB1> select * from object_customers2where id=1;
IDFIRST_NAME LAST_NAME DOB PHONE
---------- ---------- ---------- ---------------------
1 Jeff Jones 27-NOV-15 555-1212