惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Webroot Blog
Webroot Blog
U
Unit 42
A
About on SuperTechFans
宝玉的分享
宝玉的分享
月光博客
月光博客
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Securelist
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Spread Privacy
Spread Privacy
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
B
Blog
I
Intezer
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
V
V2EX
L
LangChain Blog
AI
AI
G
GRAHAM CLULEY
T
Tor Project blog
人人都是产品经理
人人都是产品经理
D
Docker
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
I
InfoQ
Y
Y Combinator Blog
C
Comments on: Blog
GbyAI
GbyAI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
H
Help Net Security
Vercel News
Vercel News
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿

博客园 - 思净

oracle中的公用同义词和私有同义词? 对C#下函数,委托,事件的一点理解! - 思净 - 博客园 经典悖论漫游(下) 经典悖论漫游中 经典悖论 精彩悖论 悖论漫谈之三 悖论漫谈(二) 经典悖论 Oracle专家高级编程学习笔记 Oracle数据库结构之物理存储结构 Oracle专家高级编程学习笔记( 二) Oracle 基本知识 简单的ORACLE存储过程 SQL子查询的一些例子 Oracle学习笔记---(三) Oracle学习笔记---(四) 掌握SQL四条最基本的数据操作语句 Oracle学习笔记---(一)
Oracle学习笔记---(五)
思净 · 2007-06-05 · via 博客园 - 思净

一,定义抽象数据类型
/*
create or replace type animal_ty as object
(breed  varchar2(25), --动物种类
name   varchar2(25), --名字
birthdate  date,     --出生日期  
member function AGE(birthdate in date) return number   --根据出生日期计算年龄
); --带有方法的抽象数据类型
*/
create or replace type animal_ty as object
(Bread varchar2(25),   --动物种类
name  varchar2(25),    --名字
hobby varchar2(10)     --爱好
);

    desc  animal_ty;
    查看  user_types;
          user_type_attrs;

二,抽象数据类型的使用

1)创建关系表
  drop  table animal;
  create table animal
  (id number primary key  ,
   anima  animal_ty
  );
  set desc depth 3
  desc animal;
2) 插入数据(使用构造方法)
  insert into  animal values(1, animal_ty('MULE','FRANCES','PLAY'));
  insert into  animal values(2, animal_ty('DOG','BENJI','EAT'));
  insert into  animal values(3, animal_ty('CROCODILE','LYLE','SWIM'));

3)操作
  查看:select f.anima.name from animal f;  
  更新: update animal f set f.anima.hobby='PLAY1' where id=1;
  删除:delete from  animal a where  a.anima.hobby='PLAY1';

2,删除对象类型
   drop type animal_ty force;

3,查询相关性
   select name,type from user_dependencies where referenced_name='ANIMAL_TY';  

4,在抽象数据类型上创建索引
  create index  Idx  on animal(anima.name);

5,final 和 not final   修饰类型
  instantiable 和not instantiable  可修饰类型和方法

默认情况下,抽象数据类型是不能被继承的,同时类型提供构造函数,类型中的方法可以被实


  声明类型加 not final 该类型可被继承    
  修饰方法: not instantiable 类型不提供方法实现
  修饰类型: not instantiable 类型没有构造函数.不能实例化

二,可变数组

1)创建VARRAY类型
    create or replace type tools_va as varray(5) of varchar2(25);
2)创建关系表,该表的字段类型是varray类型
    create table borrower(name varchar2(25) primary key,
                                     tools tools_va);
字典
select  typecode,attributes from user_types where type_name='TOOLS_VA';
select  coll_type,elem_type_owner,elem_type_name,upper_bound,
              length from user_coll_types;
3)插入数据
         insert into borrower values ('JED HOPKINS',
                                       Tools_va('HAMMER','SLEDGE','AX'));
         insert into borrower values('PK',
                                       Tools_va('PEN1','PEN2','PEN3'));
4)查看
    select * from table(select t.tools from  borrower t where t.name='PK');
  
三,嵌套表

drop type emp_ty force;
1,
create or replace type emp_ty  as object
( empno number,
   ename char(10),
   sal   number);
2,create or replace type emps_nt as table of emp_ty;

3,
create table ntdept
(
deptno number,
dname varchar2(20),
loc   varchar2(20),
dno_det emps_nt)
nested table dno_det store as emp_nt_tab;

--插入数据

insert into ntdept values
(10,'市场部','海珠北路',emps_nt(emp_ty(100,'MARRY',1000),
                                 emp_ty(101,'Lili',1500),
                                 emp_ty(102,'KHK',3000))
);


insert into ntdept values(20,'教务部','海珠南路',emps_nt(emp_ty(103,'JAKE',2200),
                                                          emp_ty(104,'ROSE',1000),
                                                          emp_ty(105,'LUSU',2000)
));

--查询
  可以使用the或table
  select deptno,dname,loc,dno_det from ntdept;
  select  dno_det from ntdept where deptno=10;
  select nt.* from table(select dno_det from ntdept where deptno=10) nt;
  select nt.* from table(select dno_det from ntdept where deptno=20) nt  where

nt.empno=103  ;
  select nt.empno,nt.ename from table(select deptno from ntdept where  deptno=10)

nt    where   nt.empno=101;
--插入
  insert into table(select dno_det from ntdept where deptno=10)  

values(106,'HANG',3000);
  或从嵌套表中选择数据插入
  insert into ntdept  values(40,'NEWd','NEWloc',
  cast(multiset(select * from table(select dno_det from ntdept where   deptno=10)

nt where nt.empno=100 )  as emps_nt))

  cast:将查询的结果转换成嵌套表的形式
  multiset:允许cast查询中包含多条记录

--更新
  update table(select dno_det from ntdept where deptno=10) nt set nt.ename='LLLL'  

where nt.empno=101;
--删除
  delete from the(select dno_det from ntdept where deptno=10) nt where

nt.empno=101

四,对象表

   1,建立对象类型
     drop type animal_ty force;
     create type animal_ty as object
     (name varchar2(15),
      hobby  varchar2(20)
     )
     /
   2,建立对象表
    create table animal of animal_ty(name constraint pk  primary key);
   3,插入数据
    insert into animal values(animal_ty('SNAKE','PLAY'));
    insert into animal values(animal_ty('DOG','SWIM'));
    insert into animal values(animal_ty('CAT','SLEEP'));

   4,查看oid
    select ref(f) from animal f;
  
   5,查看对象
    select value(r) from animal r;
  
  
使用deref

    drop table keeper;
    create table keeper
    (
     keepername  varchar2(10),
     animalkept  ref animal_ty
    )
    
    插入数据

    insert into  keeper select 'JEK',ref(f) from animal f where name='DOG';
    insert into  keeper select 'BLK',ref(f) from animal f where name='CAT';
    
    查看数据
    在关系表中看对象
    select deref(animalkept) from keeper;
  
    假设删掉一个对象
    delete from animal where name='DOG';

    select * from keeper;  还在引用该对象
    update keeper set animalkept=null where animalkept is dangling;--去掉引用
    

五,对象视图

   将dept关系表做为对象表访问

   1,建立对象类型

    create or replace type dept_type as object
    (dno number(2),
     dname varchar2(15),
     local varchar2(18)
    );
   2,建立对象视图
     create view  dept_view  of dept_type  with object oid
     (dno) as
     select * from  dept ;

   3,通过对象视图操纵关系表数据
     insert into dept_view  values(dept_type(60,'aaa','bbb'));
     delete from dept_view where deptno=60;
     结果会反映到关系表中,当改变关系表数据时,也会反映到对象视图中    

     对象视图每行都有一个oid
  
   4,当关系表之间存在引用关系时,也可以用对象视图实现  
     dept 和 emp 是主、外键表,emp表的deptno引用了dept表的deptno
     并且已为关系表dept生成了对象视图,此时关系表的每一个行都具有oid        
    
     dept表的行可以作为行对象通过dept_view视图进行访问,只要为关系表创建
     了对象视图,即可将任何关系表作为行对象进行访问
      
      --make_ref只对所提供的参数应用一个Oracle内部的算法,即可得到引用,它并没有真

正读取视图。
      select make_ref(dept_view,deptno) from dept;        
      select make_ref(dept_view,deptno) from emp;        
    
   5,通过对象视图建立引用关系  
  
     create view emp_ov as select make_ref(dept_view,deptno) dep,empno,ename,sal

from emp;  
     该视图第一列指向了对象视图dept_view的行
    
     select deref(a.dep)  from  emp_ov  a;