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

推荐订阅源

Forbes - Security
Forbes - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Palo Alto Networks Blog
Martin Fowler
Martin Fowler
T
Threatpost
D
Docker
S
Schneier on Security
M
MIT News - Artificial intelligence
G
Google Developers Blog
L
LINUX DO - 热门话题
J
Java Code Geeks
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
博客园 - Franky
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
V
Vulnerabilities – Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
人人都是产品经理
人人都是产品经理
Spread Privacy
Spread Privacy
T
Tailwind CSS Blog
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
C
CERT Recently Published Vulnerability Notes
The GitHub Blog
The GitHub Blog
Simon Willison's Weblog
Simon Willison's Weblog
NISL@THU
NISL@THU
MongoDB | Blog
MongoDB | Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Heimdal Security Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
SecWiki News
SecWiki News
P
Privacy International News Feed
P
Proofpoint News Feed
O
OpenAI News
B
Blog
腾讯CDC
F
Full Disclosure
Apple Machine Learning Research
Apple Machine Learning Research
T
Tor Project blog
H
Hacker News: Front Page
Project Zero
Project Zero
Hugging Face - Blog
Hugging Face - Blog
C
Cisco Blogs
S
Security Affairs

博客园 - Leetle

win2000/xp/2003下完全卸载ORACLE [ZT]Oracle数据库字符集问题解决方案大全 Oracle 8.1.6 for Win2000 系统文件解释 如何连接oracle数据库及故障解决办法 Oracle 9i初始化参数文件 简单冷备份恢复操作步骤 Win 下常用的oracle 9i服务的介绍 oracle初始化参数说明 Oracle中的数据字典技术初级入门 【转帖】揭露不为人所知的招聘网站的秘密, 业内人士告诉你:为何你的简历石沉大海?! 市场盈亏指标CYS的使用技巧 炒股短线招术(完整版) DBA常用SQL语句系列 Function怎么返回一个数据集 Oracle 9i 分析函数参考手册 使用Oracle的分析函数ROW_NUMBER、DENSE_RANK、RANK oracle日期处理完全版(三) oracle日期处理完全版(二) oracle日期处理完全版(一)
Oracle9i中分区partition的使用
Leetle · 2007-08-24 · via 博客园 - Leetle

第一种 范围分区
1 对表进行单列的范围分区:
这使最为常用也是最简单的方法,具体例子如下:
create table emp
(empno number(4),
ename varchar2(30),
sal number)
partition by range(empno)
(partition e1 values less than (1000) tablespace emp1,
partition e2 values less than (2000) tablespace emp2,
partition e3 values less than (maxvalue) tablespace emp3);

insert into emp values (100,'Tom',1000);
insert into emp values (500,'Peter',2000);
insert into emp values (1000,'Scott',3000);
insert into emp values (1999,'Bill',4000);
insert into emp values (5000,'Gates',6000);
commit;

从emp表中选择全部的纪录如下:
SQL> select * from emp;

EMPNO ENAME SAL
---------- ------------------------------ ----------
100 Tom 1000
500 Peter 2000
1000 Scott 3000
1999 Bill 4000
5000 Gates 6000

还可以按照分区进行选择:
SQL> select * from emp partition (e1);
EMPNO ENAME SAL
---------- ------------------------------ ----------
100 Tom 1000
500 Peter 2000

SQL> select * from emp partition (e2)
EMPNO ENAME SAL
---------- ------------------------------ ----------
1000 Scott 3000
1999 Bill 4000

SQL> select * from emp partition (e3)
EMPNO ENAME SAL
---------- ------------------------------ ----------
5000 Gates 6000

使用了分区,还可以单独针对指定的分区进行truncate操作:
alter table emp truncate partition e2;

2 对表进行多列的范围分区:
多列的范围分区主要是基于表中多个列的值的范围对数据进行分区,例如:
drop table emp;
create table emp
(empno number(4),
ename varchar2(30),
sal number,
day integer not null,
month integer not null)
partition by range(month,day)
(partition e1 values less than (5,1) tablespace emp1,
partition e2 values less than (10,2) tablespace emp2,
partition e3 values less than (maxvalue,maxvalue) tablespace emp3);

SQL> insert into emp values (100,'Tom',1000,10,6);
SQL> insert into emp values (200,'Peter',2000,3,1);
SQL> insert into emp values (300,'Jane',3000,23,11);

第二种 Hash分区:
hash分区最主要的机制是根据hash算法来计算具体某条纪录应该插入到哪个分区中
(问:hash算法是干什么的?呵呵,只能去看看数据结构了)
hash算法中最重要的是hash函数,Oracle中如果你要使用hash分区,只需指定分区的数量即可
建议分区的数量采用2的n次方,这样可以使得各个分区间数据分布更加均匀
具体例子如下:
drop table emp;
create table emp (
empno number(4),
ename varchar2(30),
sal number)
partition by hash (empno)
partitions 8
store in (emp1,emp2,emp3,emp4,emp5,emp6,emp7,emp8);
怎么样?很方便吧!

第三种 复合分区:
这是一种将前两种分区综合在一起使用的方法,例如:
drop table emp;
create table emp (
empno number(4),
ename varchar2(30),
hiredate date)
partition by range (hiredate)
subpartition by hash (empno)
subpartitions 2
(partition e1 values less than (to_date('20020501','YYYYMMDD')),
partition e2 values less than (to_date('20021001','YYYYMMDD')),
partition e3 values less than (maxvalue));
上面的例子中将雇员表先按照雇佣时间hiredate进行了范围分区,然后再把每个分区分为两个子hash分区。例子中一共将产生6个分区。

第四种 列表分区:
这是Oracle 9i的新特性,有了这种分区使得我们可以方便的按照值来将数据分为更小的片断。
例如:
drop table emp;
create table emp (
empno number(4),
ename varchar2(30),
location varchar2(30))
partition by list (location)
(partition e1 values ('北京'),
partition e2 values ('上海','天津','重庆'),
partition e3 values ('广东','福建'));
这里说明一下,列表分区不能有maxvalue,当你试图insert列表中不存在的值的时候,Oracle会拒绝这条纪录(ORA-14400)。
怎么样?看出列表分区很有用了吧?这么方便的东东居然是Oracle9i的New Feature,分特!

上面列出了Oracle9i中使用分区的四种方法,其中的例子很简单,真正工作中具体使用那种分区方法要参考你的具体需求。

注:例子中使用的e1,e2,e3,e4等是分区名称,emp1,emp2,emp3,emp4等是表空间名称