Oracle中对象操作示例(二)
2
is
begin
return name||':'||province||','||city||','||street||','||doorplate;
end;
end;
create table t_housemaster of hm_type;
insert into t_housemaster values('北京','北京','长安街','20号','张朋');
insert into t_housemaster values('上海','上海','外滩','20号','王胜');
commit;
select * from t_housemaster;
create table t_housemaster_ex(
id number(8) primary key,
name varchar2(10),
master ref hm_type);
insert into t_housemaster_ex select 1,'张朋',ref(a) from t_housemaster a where a.name='张朋';
select a.id,a.name,rawtohex(a.master) ,deref(a.master).info() mi from t_housemaster_ex a;
--master字段中仅存的是raw格式的地址。指向实际存储的内容所在的位置。
--更对参照类型所指的对象,再查查看。
update t_housemaster set street='23号' where name='张朋';
select a.id,a.name,deref(a.master).info() mi from t_housemaster_ex a;
--增加对象属性
alter type employee_type ADD ATTRIBUTE
remark varchar2(50) cascade;
--使用对象创建的表结构自动发生了变化
desc t_employee_object
--使用该对象定义的字段,也自动增加上了该属性。值为NULL
select a.basic_info.remark from t_employee_ex a;
select dump(a.basic_info) from t_employee_ex a;
select a.basic_info.eno ,a.basic_info.name from t_employee_ex a where a.basic_info.eno=3333;