您的位置:首页 > 其它

对象标识符和对象引用+对象标识符+对象引用+为对象引用插入数据+查询对象引用OID对应的实际值+更新对象引用+删除对象引用

2017-06-02 22:21 495 查看
对象标识符和对象引用

测试数据

--创建对象类型class3
--创建对象类型头
create or replace  type class3 as object (
id number,
name varchar2 ( 20 ),
member  function get_name(no varchar2) return varchar2
) ;

--创建对象体
create or replace type body class3 as
member  function get_name(no varchar2) return varchar2 as
name varchar2(20);
begin
select sname into name from zhou.student where sno=no ;
return name;
end;
end;

--创建对象类型studentfar,里面有列对象class3
create or replace  type studentfar  as object (
sid number,
sname varchar2 ( 20 ),
class class3
) ;

--创建对象表
create table studentson of studentfar;

--插入数据
insert into studentson values(11,'丽丽',class3(1101,'语文'));
insert into studentson values(11,'丽丽',class3(1102,'数学'));


对象标识符(OID)

1对象表中的每一个对象都有唯一的对象标识符(Object identifier,OID)

2OID存储在名称为ref的列中

3OID表示数据库中对象的位置,可以将OID存储在对象引用中,通过他就可以访问它引用的对象

举例

select ref(s) from studentson s where s.class.id=1101;




ref(s)的值就是OID。

对象引用

1对象引用使用ref类型进行定义,通常用作指向对象表中对象的指针

2对象引用可以为对象表之间的关系建立模型,而不是使用外键。

语法

create table tabe_name(

ref_name ref type_name scope is table_type_name

);

scope is:将对象引用限制在特定表中的对象上

举例

create table school(
id number,
class_ref ref studentfar scope is studentson);




为对象引用插入数据

insert into school values(1,(select ref(s) from studentson s where s.class.id=1101));
select * from school;
select class_ref from school;






查询对象引用OID对应的实际值

select id,deref(class_ref) from school;
select id,deref(class_ref).sid,deref(class_ref).sname,deref(class_ref).class.id,deref(class_ref).class.name  from school;




更新对象引用

update school set class_ref=((select ref(s) from studentson s where s.class.id=1102))
where id=1;
select id,deref(class_ref).sid,deref(class_ref).sname,deref(class_ref).class.id,deref(class_ref).class.name  from school;




删除对象引用

delete school where  id=1;
select id,deref(class_ref).sid,deref(class_ref).sname,deref(class_ref).class.id,deref(class_ref).class.name  from school;


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐