- 浏览: 440375 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (162)
- easymock (3)
- 模板引擎 (3)
- JForum (4)
- web (9)
- spring (10)
- java (20)
- struts (9)
- uml (3)
- java pattern (19)
- JQuery (14)
- 多线程 (13)
- database (21)
- PS (3)
- ejb (6)
- 版本管理 svn , maven , ant (2)
- protocol (1)
- 测试 (1)
- ws (7)
- Apache (4)
- 脚本语言 (1)
- guice (1)
- 分布式 (4)
- 架构 (0)
- 经验 (1)
- 版本管理 svn (1)
- maven (1)
- ant (1)
- 书籍 (1)
- Linux (1)
最新评论
-
Master-Gao:
稍微明白了点,,有点萌萌哒
为什么匿名内部类参数必须为final类型 -
waw0931:
终于明白了,谢谢!
为什么匿名内部类参数必须为final类型 -
十三圆桌骑士:
提供了两个链接还是有用的。
安装Mondrian -
放方芳:
[flash=200,200][/flash]
Freemarker标签使用 -
放方芳:
[b][/b]
Freemarker标签使用
Oracle嵌套表的使用
1. 创建对象类型
create or replace type scott.depscore_type as OBJECT(
depid number(4),
score number
);
2. 创建表类型
create or replace type scott.depscore_tab_type as table of scott.depscore_type;
3. 创建嵌套表(使用嵌套表作为表列)
create table scott.befscore(
proid number,
depscore scott.depscore_tab_type)
nested table depscore store as depscoretab;
4. 向嵌套表中插入数据
insert into scott.befscore values(1,scott.depscore_tab_type(scott.depscore_type(1,1),scott.depscore_type(2,2)));
insert into scott.befscore values(2,scott.depscore_tab_type(scott.depscore_type(2,2),scott.depscore_type(3,4)));
insert into scott.befscore values(3,scott.depscore_tab_type(scott.depscore_type(3,5),scott.depscore_type(5,5)));
commit;
5. 查询嵌套表中的数据
select * from table(select depscore from scott.befscore where proid=1);
或者select * from the(select depscore from scott.befscore where proid=1);
注:在这里the和table意思一样
select e.* from scott.befscore,table(depscore) e where proid=1;
DEPID SCORE
1 1
2 2
select * from table(select depscore from scott.befscore where proid=2) where depid=2;
DEPID SCORE
2 2
select * from scott.befscore;
PROID DEPSCORE(DEPID, SCORE)
1 DEPSCORE_TAB_TYPE(DEPSCORE_TYPE(1, 1), DEPSCORE_TYPE(2, 2))
2 DEPSCORE_TAB_TYPE(DEPSCORE_TYPE(2, 2), DEPSCORE_TYPE(3, 4))
3 DEPSCORE_TAB_TYPE(DEPSCORE_TYPE(3, 5), DEPSCORE_TYPE(5, 5))
select value(e) from scott.befscore,table(depscore) e;
VALUE(E)(DEPID, SCORE)
DEPSCORE_TYPE(1, 1)
DEPSCORE_TYPE(2, 2)
DEPSCORE_TYPE(2, 2)
DEPSCORE_TYPE(3, 4)
DEPSCORE_TYPE(3, 5)
DEPSCORE_TYPE(5, 5)
select e.depid id编号,score from scott.befscore,table(depscore) e;
ID编号 SCORE
1 1
2 2
2 2
3 4
3 5
5 5
6. 插入嵌套表中的值
insert into table(select depscore from scott.befscore where proid=1) values(8,8);
7. 修改嵌套表
update scott.befscore set depscore=scott.depscore_tab_type(scott.depscore_type(9,9)) where proid =1;
输出结果是:
select e.* from scott.befscore,table(depscore) e where proid=1;
DEPID SCORE
9 9
8. 删除表
delete from scott.befscore where proid=1;
----------------邪恶的分割线------------------
假设有一个关于动物饲养员的表,希望其中具有他们饲养的动物的信息。用一个嵌套表,就可以在同一个表中存储饲养员和其饲养的全部动物的信息。
1、创建类型animal_ty:此类型中,对于每个动物都包含有一个记录,记载了其品种、名称和出生日期信息。
CREATE TYPE animal_ty AS OBJECT (
breed varchar2(25),
name varchar2(25),
birthdate date);
2、创建animals_nt:此类型将用作一个嵌套表的基础类型。
CREATE TYPE animals_nt as table of animal_ty;
3、创建表breeder:饲养员的信息表
create table breeder
(breedername varchar2(25),
animals animal_nt)
nested table animals store as animals_nt_tab;
4、向嵌套表中插入记录
insert into breeder
values( 'mary ',animal_nt(animal_ty( 'dog ', 'butch ', '31-MAR-97 '),
animal_ty( 'dog ', 'rover ', '31-MAR-97 '),
animal_ty( 'dog ', 'julio ', '31-MAR-97 ')));
insert into breeder
values( 'jane ',animal_nt(animal_ty( 'cat ', 'an ', '31-MAR-97 '),
animal_ty( 'cat ', 'jame ', '31-MAR-97 '),
animal_ty( 'cat ', 'killer ', '31-MAR-97 ')));
commit;
5、查询嵌套表
select name,birthdate from
table(select animals from breeder);
select name,birthdate from
table(select animals from breeder
where breedername=’mary’)
where name=’dog’;
三、嵌套表的特点:
1、对象复用:如果编写面向对象的代码,就提高了重用以前编写的代码模块的机会。同样,如果创建面向对象的数据库对象,也就提高了数据库对象能够被重用的机会。
2、标准支持:如果创建标准的对象,那么它们被重用的机会就会提高。如果有多个应用或多个表使用同一数据库对象集合,那么它就是既成事实的数据库对象标准。
3、定义访问路径:对于每一个对象,用户可定义在其上运行的过程和函数,从而可以使数据和访问此数据的方法联合起来。有了用这种方式定义的访问路径,就可以标准化数据访问的方法并提高对象的可复用性。
可变数组
一、可变数组的定义:
可变数组与嵌套表相似,也是一种集合。一个可变数组是对象的一个集合,其中每个对象都具有相同的数据类型。可变数组的大小由创建时决定。在表中建立可变数组后,可变数组在主表中作为一个列对待。从概念上讲,可变数组是一个限制了行集合的嵌套表。
可变数组,允许用户在表中存储重复的属性。例如:假设用户有一个project表,并在项目中指定了工作人员,一个项目可以有多个工人,而一个工人也可以为多个项目工作。在严格的关系模型中,用户可以创建一个project表,一个worker表和存储它们之间关系的交叉表project_worker。
用户可使用可变数组在project表中存储工人的名字。如果项目限定的工人数不超过10人,可以建立一个以10个数据项为限的可变数组。接下来就可处理此可变数组,从而对于每一个项目,可以选取其中所有工人的名字,而勿需查询表worker。
二、举例说明可变数组的使用:
1、创建类型comm_info
CREATE TYPE comm_info AS OBJECT ( /*此类型为通讯方式的集合
no number(3), /*通讯类型号
comm_type varchar2(20), /*通讯类型
comm_no varchar2(30)); /*号码
2、创建可变数组comm_info_list
CREATE TYPE comm_info_list AS
VARRAY(50) OF comm_info;
3、创建表
create table user_info
(user_id number(6), /*用户ID号
user_name varchar2(20), /*用户名称
user_comm comm_info_list); /*与用户联系的通讯方式
4、向可变数组插入记录
insert into user_info
values(1, 'mary ',comm_info_list(comm_info(1, '手机 ', '13651401919 '),
comm_info(2, '呼机 ', '1281234567 ')));
insert into user_info
values(2, 'carl ',comm_info_list(comm_info(1, '手机 ', '13901018888 '),
comm_info(2, '呼机 ', '1281234567 ')));
commit;
5、查询可变数组
select user_comm from user_info
where user_id=1;
select comm_type,comm_no
from table(select user_comm from user_info
where user_id=1)
where no=1;
与一位用户联系的方式有很多种,比如:手机、呼机、座机等。在一个严格的关系模型中,将需要两个独立的表:用户信息和通讯方式,而在可变数组中,允许在表user_info中直接访问用户的联系方式,这种不经联合而直接选择数据的能力使得用户对数据的访问更加容易
1. 创建对象类型
create or replace type scott.depscore_type as OBJECT(
depid number(4),
score number
);
2. 创建表类型
create or replace type scott.depscore_tab_type as table of scott.depscore_type;
3. 创建嵌套表(使用嵌套表作为表列)
create table scott.befscore(
proid number,
depscore scott.depscore_tab_type)
nested table depscore store as depscoretab;
4. 向嵌套表中插入数据
insert into scott.befscore values(1,scott.depscore_tab_type(scott.depscore_type(1,1),scott.depscore_type(2,2)));
insert into scott.befscore values(2,scott.depscore_tab_type(scott.depscore_type(2,2),scott.depscore_type(3,4)));
insert into scott.befscore values(3,scott.depscore_tab_type(scott.depscore_type(3,5),scott.depscore_type(5,5)));
commit;
5. 查询嵌套表中的数据
select * from table(select depscore from scott.befscore where proid=1);
或者select * from the(select depscore from scott.befscore where proid=1);
注:在这里the和table意思一样
select e.* from scott.befscore,table(depscore) e where proid=1;
DEPID SCORE
1 1
2 2
select * from table(select depscore from scott.befscore where proid=2) where depid=2;
DEPID SCORE
2 2
select * from scott.befscore;
PROID DEPSCORE(DEPID, SCORE)
1 DEPSCORE_TAB_TYPE(DEPSCORE_TYPE(1, 1), DEPSCORE_TYPE(2, 2))
2 DEPSCORE_TAB_TYPE(DEPSCORE_TYPE(2, 2), DEPSCORE_TYPE(3, 4))
3 DEPSCORE_TAB_TYPE(DEPSCORE_TYPE(3, 5), DEPSCORE_TYPE(5, 5))
select value(e) from scott.befscore,table(depscore) e;
VALUE(E)(DEPID, SCORE)
DEPSCORE_TYPE(1, 1)
DEPSCORE_TYPE(2, 2)
DEPSCORE_TYPE(2, 2)
DEPSCORE_TYPE(3, 4)
DEPSCORE_TYPE(3, 5)
DEPSCORE_TYPE(5, 5)
select e.depid id编号,score from scott.befscore,table(depscore) e;
ID编号 SCORE
1 1
2 2
2 2
3 4
3 5
5 5
6. 插入嵌套表中的值
insert into table(select depscore from scott.befscore where proid=1) values(8,8);
7. 修改嵌套表
update scott.befscore set depscore=scott.depscore_tab_type(scott.depscore_type(9,9)) where proid =1;
输出结果是:
select e.* from scott.befscore,table(depscore) e where proid=1;
DEPID SCORE
9 9
8. 删除表
delete from scott.befscore where proid=1;
----------------邪恶的分割线------------------
假设有一个关于动物饲养员的表,希望其中具有他们饲养的动物的信息。用一个嵌套表,就可以在同一个表中存储饲养员和其饲养的全部动物的信息。
1、创建类型animal_ty:此类型中,对于每个动物都包含有一个记录,记载了其品种、名称和出生日期信息。
CREATE TYPE animal_ty AS OBJECT (
breed varchar2(25),
name varchar2(25),
birthdate date);
2、创建animals_nt:此类型将用作一个嵌套表的基础类型。
CREATE TYPE animals_nt as table of animal_ty;
3、创建表breeder:饲养员的信息表
create table breeder
(breedername varchar2(25),
animals animal_nt)
nested table animals store as animals_nt_tab;
4、向嵌套表中插入记录
insert into breeder
values( 'mary ',animal_nt(animal_ty( 'dog ', 'butch ', '31-MAR-97 '),
animal_ty( 'dog ', 'rover ', '31-MAR-97 '),
animal_ty( 'dog ', 'julio ', '31-MAR-97 ')));
insert into breeder
values( 'jane ',animal_nt(animal_ty( 'cat ', 'an ', '31-MAR-97 '),
animal_ty( 'cat ', 'jame ', '31-MAR-97 '),
animal_ty( 'cat ', 'killer ', '31-MAR-97 ')));
commit;
5、查询嵌套表
select name,birthdate from
table(select animals from breeder);
select name,birthdate from
table(select animals from breeder
where breedername=’mary’)
where name=’dog’;
三、嵌套表的特点:
1、对象复用:如果编写面向对象的代码,就提高了重用以前编写的代码模块的机会。同样,如果创建面向对象的数据库对象,也就提高了数据库对象能够被重用的机会。
2、标准支持:如果创建标准的对象,那么它们被重用的机会就会提高。如果有多个应用或多个表使用同一数据库对象集合,那么它就是既成事实的数据库对象标准。
3、定义访问路径:对于每一个对象,用户可定义在其上运行的过程和函数,从而可以使数据和访问此数据的方法联合起来。有了用这种方式定义的访问路径,就可以标准化数据访问的方法并提高对象的可复用性。
可变数组
一、可变数组的定义:
可变数组与嵌套表相似,也是一种集合。一个可变数组是对象的一个集合,其中每个对象都具有相同的数据类型。可变数组的大小由创建时决定。在表中建立可变数组后,可变数组在主表中作为一个列对待。从概念上讲,可变数组是一个限制了行集合的嵌套表。
可变数组,允许用户在表中存储重复的属性。例如:假设用户有一个project表,并在项目中指定了工作人员,一个项目可以有多个工人,而一个工人也可以为多个项目工作。在严格的关系模型中,用户可以创建一个project表,一个worker表和存储它们之间关系的交叉表project_worker。
用户可使用可变数组在project表中存储工人的名字。如果项目限定的工人数不超过10人,可以建立一个以10个数据项为限的可变数组。接下来就可处理此可变数组,从而对于每一个项目,可以选取其中所有工人的名字,而勿需查询表worker。
二、举例说明可变数组的使用:
1、创建类型comm_info
CREATE TYPE comm_info AS OBJECT ( /*此类型为通讯方式的集合
no number(3), /*通讯类型号
comm_type varchar2(20), /*通讯类型
comm_no varchar2(30)); /*号码
2、创建可变数组comm_info_list
CREATE TYPE comm_info_list AS
VARRAY(50) OF comm_info;
3、创建表
create table user_info
(user_id number(6), /*用户ID号
user_name varchar2(20), /*用户名称
user_comm comm_info_list); /*与用户联系的通讯方式
4、向可变数组插入记录
insert into user_info
values(1, 'mary ',comm_info_list(comm_info(1, '手机 ', '13651401919 '),
comm_info(2, '呼机 ', '1281234567 ')));
insert into user_info
values(2, 'carl ',comm_info_list(comm_info(1, '手机 ', '13901018888 '),
comm_info(2, '呼机 ', '1281234567 ')));
commit;
5、查询可变数组
select user_comm from user_info
where user_id=1;
select comm_type,comm_no
from table(select user_comm from user_info
where user_id=1)
where no=1;
与一位用户联系的方式有很多种,比如:手机、呼机、座机等。在一个严格的关系模型中,将需要两个独立的表:用户信息和通讯方式,而在可变数组中,允许在表user_info中直接访问用户的联系方式,这种不经联合而直接选择数据的能力使得用户对数据的访问更加容易
发表评论
-
安装Mondrian
2014-04-11 10:48 4618Mondrian and OLAP Mondrian i ... -
NoSql 笔记
2014-02-18 17:39 737看了一些关于NoSql的文 ... -
mysql explain用法
2014-02-14 11:53 913补充一点: id 就是 sql 语句中 select 出现 ... -
数据库范式概念解析(第一范式,第二范式,第三范式)
2013-02-26 10:17 1096大部分数据库从业人员 ... -
ORACLE数据库基础知识
2013-02-23 11:39 852http://wenku.baidu.com/view/958 ... -
Oracle 的性能优化概述
2013-02-23 11:34 1039Oracle 的性能优化概 ... -
mysql 索引
2013-02-23 11:33 943索引是一种特殊的文件(InnoDB数据表上的索引是表空间的一 ... -
hibernate规则
2012-12-18 14:58 1080实体类的编写规则 l 实体类必须具备无参 ... -
Hibernate 关联关系映射(Association Relationship Mapping)
2012-12-17 18:55 949一对一主键关联 数据表为:夫妻表 POJO 为 ... -
关系型数据库性能优化总结(转)
2012-06-13 14:17 824关系型数据库性能优化 ... -
spring+hibernate架构中Dao访问数据库的几种方法
2011-11-28 18:10 1396spring+hibernate架构中Dao访问数据库的几种方 ... -
mybatis 缓存(二)
2011-10-20 13:05 5333缓存不适合情况:select ... -
mybatis 缓存(一)
2011-10-20 11:27 1250缓存概述 http://www.iteye.com/topi ... -
mybatis 基本
2011-10-20 11:14 1449今天刚听说iBATIS改名为MyBatis,实际上就是iBAT ... -
hibernate 延迟加载(一)
2011-10-12 10:03 937首先是第一个误区:延迟加载只能作用于关联实体 看到这个是不 ... -
mybatis 多对多 处理
2011-09-26 18:41 42025下面的例子让新手看 ... -
MyBatis+Spring基于接口编程的原理分析
2011-09-17 15:57 3414整合Spring3及MyBatis3 对于整合Sprin ... -
解释 关闭statement 和rs
2010-09-19 13:14 2317很多朋友在Java开发中, ... -
HIBERNATE
2010-07-30 11:51 859使用java进行项目开发也有不少年头了,应用从网站到金融产品到 ... -
延迟加载
2010-07-11 14:04 1314could not initialize proxy - no ...
相关推荐
oracle中的数组使用 oracle中的数组使用 oracle中的数组使用 oracle中的数组使用 oracle中的数组使用 oracle中的数组使用
ORACLE数组使用方法,文档,详细介绍Oracle中数组如何使用
Oracle学习笔记(嵌套表、可变数组),有具体的代码案例供大家参考
ORACLE存储过程中定义数组并且判断某值是否在数组中。有例子可執行、 、有例子可執行、
最近在oracle 中用到拆分字符串返回数组,一直头痛,因为在 oracle 中没有类似java中有split 函数 ,所以要自己写。好不容搜到一个。那网上是到处都是这个代码。怎么找都是这个方法,我就用了。这个方法如下: ...
Oracle嵌套表使用和存储分析.doc
oracle中存储过程和定义方法时使用的数组形式
oracle数组操作,包含固定数组、可变数组、可变数组取表
基于oracle的数组实现,使用自定义类型的方式实现
主要介绍了oracle中变长数组varray,嵌套表,集合使用方法,需要的朋友可以参考下
c#调用Oracle UDT自定义结构数组类型源代码
java调用oracle输出参数为多行多列的结构化数组的存储过程,并将其遍历解析;该demo部署后,只需要配置poolman.xml数据源,即可运行;
oracle锁表查询oracle锁表查询oracle锁表查询oracle锁表查询
4. 使用JAVA存储过程(通过POI包,这也是本文的重点) 4.1至http://poi.apache.org 下载POI包,注意与ORACLE JVM版本匹配 (旧版本的POI下载:http://archive.apache.org/dist/jakarta/poi/release/bin/)。至ORACL官网...
这是因为ORACLE只对简单的表提供高速缓冲(cache buffering) ,这个功能并不适用于多表连接查询..数据库管理员必须在init.ora中为这个区域设置合适的参数,当这个内存区域越大,就可以保留更多的语句,当然被共享的可能性...
一些ORACLE的表链接查询。求最高,最低,排序
oracle查询表碎片语句
Oracle 多表查询优化
Oracle+表连接方式(内连接-外连接-自连接)+详解