create table ware_retail_part --创建一个描述商品零售的数据表
(
id integer primary key,--销售编号
retail_date date,--销售日期
ware_name varchar2(50)--商品名称
)
partition by range(retail_date)
(
--2011年第一个季度为part_01分区
partition par_01 values less than(to_date('2011-04-01','yyyy-mm-dd')) tablespace TBSP_1,
--2011年第二个季度为part_02分区
partition par_02 values less than(to_date('2011-07-01','yyyy-mm-dd')) tablespace TBSP_1,
--2011年第三个季度为part_03分区
partition par_03 values less than(to_date('2011-10-01','yyyy-mm-dd')) tablespace TBSP_2,
--2011年第四个季度为part_04分区
partition par_04 values less than(to_date('2012-01-01','yyyy-mm-dd')) tablespace TBSP_2
);
create table ware_retail_part2 --创建一个描述商品零售的数据表
(
id integer primary key,--销售编号
retail_date date,--销售日期
ware_name varchar2(50)--商品名称
)
partition by range(id,retail_date)--按照销售序号和销售日期分区
(
--第一个分区part_01
partition par_01 values less than(10000,to_date('2011-12-01','yyyy-mm-dd')) tablespace TBSP_1,
--第一个分区part_02
partition par_02 values less than(20000,to_date('2012-12-01','yyyy-mm-dd')) tablespace TBSP_1,
--第一个分区part_03
partition par_03 values less than(maxvalue,maxvalue) tablespace TBSP_2
);
create table ware_retail_part3 --创建一个描述商品零售的数据表
(
id integer primary key,--销售编号
retail_date date,--销售日期
ware_name varchar2(50)--商品名称
)
partition by hash(id)
(
partition par_01 tablespace TBSP_1,
partition par_02 tablespace TBSP_2
);
create table person
(
id number primary key,
name varchar2(20),
sex varchar2(2)
)
partition by hash(id)
partitions 2
store in(tbsp_1,tbsp_2);
create table goods
(
id number,
goodname varchar2(50)
)
storage(initial 2048k)
partition by hash(id)
(
partition par1 tablespace tbsp_1,
partition par2 tablespace tbsp_2
);
create table clients
(
id integer primary key,
name varchar2(50),
province varchar2(20)
)
partition by list(province)
(
partition shandong values('山东省'),
partition guangdong values('广东省'),
partition yunnan values('云南省')
);
 create table person2                     --创建以一个描述个人信息的表
(
id number primary key, --个人的编号
name varchar2(20), --姓名
sex varchar2(2) --性别
)
partition by range(id)--以id作为分区键创建范围分区
subpartition by hash(name)--以name列作为分区键创建hash子分区
subpartitions 2 store in(tbsp_1,tbsp_2)--hash子分区公有两个,分别存储在两个不同的命名空间中
(
partition par1 values less than(5000),--范围分区,id小于5000
partition par2 values less than(10000),--范围分区,id小于10000
partition par3 values less than(maxvalue)--范围分区,id不小于10000
);
create table saleRecord
(
id number primary key, --编号
goodsname varchar2(50),--商品名称
saledate date,--销售日期
quantity number--销售量
)
partition by range(saledate)
interval (numtoyminterval(1,'year'))
(
--设置分区键值日期小于2012-01-01
partition par_fist values less than (to_date('2012-01-01','yyyy-mm-dd'))
);
alter table clients
add partition hebei values('河北省')
storage(initial 10K next 20k) tablespace tbsp_1
nologging;
--创建表和分区
create table sales--创建一个销售记录表
(
id number primary key,--记录编号
goodsname varchar2(10),--商品名
saledate date--销售日期
)
partition by range(saledate)--按照日期分区
(
--第一季度数据
partition part_sea1 values less than(to_date('2011-04-01','yyyy-mm-dd')) tablespace tbsp_1,
--第二季度数据
partition part_sea2 values less than(to_date('2011-07-01','yyyy-mm-dd')) tablespace tbsp_2,
--第三季度数据
partition part_sea3 values less than(to_date('2011-10-01','yyyy-mm-dd')) tablespace tbsp_1,
--第四季度数据
partition part_sea4 values less than(to_date('2012-01-01','yyyy-mm-dd')) tablespace tbsp_2
); --创建局部索引
create index index_3_4 on sales(saledate)
local(
partition part_seal tablespace tbsp_1,
partition part_sea2 tablespace tbsp_2,
partition part_sea3 tablespace tbsp_1,
partition part_sea4 tablespace tbsp_2
); --并入分区
alter table sales merge partitions part_sea3,part_sea4 into partition part_sea4; --重建局部索引
alter table sales modify partition part_sea4 rebuild unusable local indexes;
--创建3个表空间

create tablespace ts_1 datafile 'D:\OracleFiles\OracleData\ts1.dbf'
size 10m
extent management local autoallocate;
create tablespace ts_2 datafile 'D:\OracleFiles\OracleData\ts2.dbf'
size 10m
extent management local autoallocate;
create tablespace ts_3 datafile 'D:\OracleFiles\OracleData\ts3.dbf'
size 10m
extent management local autoallocate; --创建分区表
create table studentgrade
(
id number primary key,--记录id
name varchar2(10),--学生名称
subject varchar2(10),--学科
grade number --成绩
)
partition by range(grade)
(
--小于60分,不及格
partition par_nopass values less than(60) tablespace ts_1,
--小于70分,及格
partition par_pass values less than(70) tablespace ts_2,
--大于或等于70分,优秀
partition par_good values less than(maxvalue) tablespace ts_3
); --创建本地索引分区
create index grade_index on studentgrade(grade)
local--根据表分区创建本地索引分区
(
partition p1 tablespace ts_1,
partition p2 tablespace ts_2,
partition p3 tablespace ts_3
); --查询所创建的索引分区信息
select partition_name,tablespace_name from dba_ind_partitions where index_name = 'GRADE_INDEX';
create index index_SalePrice on Books(SalePrice)
global partition by range(SalePrice)
(
partition p1 values less than (30),
partition p2 values less than (50),
partition p3 values less than (maxvalue)
);
create index index_ISBN on books(ISBN)
global partition by hash(ISBN);
alter index index_saleprice rename partition p3 to p_new;
 create table Books_Sale                        --图书销售表
(
id integer primary key, --编号
quantity number, --销售数量
book_name varchar2(50), --名称
publisher varchar2(50) --出版社
)
partition by list(publisher) --以publisher 列为分区键创建列表分区
(
partition A values('A省出版社'), --A省份
partition B values('B省出版社'), --B省份
partition C values('C省出版社') --C省份
);
create index grade_index on Books_Sale(publisher)
local --根据表分区创建本地索引分区
(
partition p1 tablespace users,
partition p2 tablespace users,
partition p3 tablespace users
);

吴裕雄--天生自然ORACLE数据库学习笔记:表分区与索引分区的更多相关文章

  1. 吴裕雄--天生自然ORACLE数据库学习笔记:Oracle数据备份与恢复

    run{ allocate channel ch_1 device type disk format = 'd:\oraclebf\%u_%c.bak'; backup tablespace syst ...

  2. 吴裕雄--天生自然ORACLE数据库学习笔记:过程、函数、触发器和包

    create procedure pro_insertDept is begin ,'市场拓展部','JILIN'); --插入数据记录 commit; --提交数据 dbms_output.put_ ...

  3. 吴裕雄--天生自然ORACLE数据库学习笔记:PL/SQL编程

    set serveroutput on declare a ; b ; c number; begin c:=(a+b)/(a-b); dbms_output.put_line(c); excepti ...

  4. 吴裕雄--天生自然ORACLE数据库学习笔记:Oracle 11g的闪回技术

    alter system set db_recovery_file_dest_size=4g scope=both; connect system/1qaz2wsx as sysdba; archiv ...

  5. 吴裕雄--天生自然ORACLE数据库学习笔记:数据导出与导入

    create directory dump_dir as 'd:\dump'; grant read,write on directory dump_dir to scott; --在cmd下 exp ...

  6. 吴裕雄--天生自然ORACLE数据库学习笔记:优化SQL语句

    create or replace procedure trun_table(table_deleted in varchar2) as --创建一个存储过程,传入一个表示表名称的参数,实现清空指定的 ...

  7. 吴裕雄--天生自然ORACLE数据库学习笔记:Oracle系统调优

    --修改 alter system set large_pool_size=64m; --显示 show parameter large_pool_size; select sum(getmisses ...

  8. 吴裕雄--天生自然ORACLE数据库学习笔记:用户管理与权限分配

    create user mr identified by mrsoft default tablespace users temporary tablespace temp; create user ...

  9. 吴裕雄--天生自然ORACLE数据库学习笔记:其它数据对象

    create index emp_deptno_index on emp(deptno) pctfree tablespace users; create bitmap index emp_salar ...

随机推荐

  1. 【游戏体验】Buttonhunt(鼠标寻找按钮)

    虽然画风千奇百变 但这款益智游戏的趣味性相当高 推荐试玩 个人测评 游戏性 9/10 音乐 4/10 剧情 6/10 总评 19/30

  2. cordova的安装与配置

    1.安装nodejs(自动包含npm) 2.在命令行中通过npm语句npm install -g cordova 安装cordova(如果提示网络连接失败,需要设置网络代理,搭理网址:npm conf ...

  3. 【读书笔记】--《编写高质量iOS与OS X代码的52个有效方法》

    1.Objective-C 起源: 在 C 语言基础上添加了面向对象特性,是 C 语言的超集.Objective-C 由 SmallTalk 语言演变过来,使用消息结构,运行环境由运行环境决定. OC ...

  4. via/route blockage/size blockage/wire/pin guide/pin blockage/partition

    1.via 中文名称互连线通孔.我们知道,芯片的连线有不同层的金属互连线相互连接.而Via的作用就是连接这些不同层的金属.如下图所示: 一个完整的通孔是由三层组成的,包括两个互连层和一个cut层,cu ...

  5. Anaconda"无法定位程序输入点 OPENSSL_sk_new_reserve 于动态链接库Anaconda3\Library\bin\libssl-1_1-x64.dll上"的解决办法

    Anaconda"无法定位程序输入点 OPENSSL_sk_new_reserve 于动态链接库Anaconda3\Library\bin\libssl-1_1-x64.dll上" ...

  6. Angular的启动过程

    我们知道由命令 ng new project-name,cli将会创建一个基础的angular应用,我们是可以直接运行起来一个应用.这归功与cli已经给我们创建好了一个根模块AppModule,而根模 ...

  7. 图片的onerror 事件解析

    1. 该事件触发条件 文档和图像在加载失败的时候(用户体验会下降.)会触发该事件 2. 解决碎图的办法 利用img的onerror事件和javascript 例: 现有的图片是 successed.p ...

  8. 推荐算法之---FM算法;

    一,FM算法: 1,逻辑回归上面进行了交叉特征.算法复杂度优化从O(n^3)->O(k*n^2)->O(k*n). 2,本质:每个特征都有一个k维的向量,代表的是每个特征都有k个不可告人的 ...

  9. T114048 [RC-02] yltx数对 (打表)

    这题如果全部打表的话,文件大小会有65kb,超了,所以只打出一半,前一半用程序算就可以了,并不会超时. 如果算法优化的好,其实可以打的更少. #include <bits/stdc++.h> ...

  10. JAVA基础学习(6)之使用对象

    6使用对象 6.1字符类型 6.1.1字符类型 char和int互相转换 //a比A大32 Scanner in=new Scanner(System.in); char c='B'; char c1 ...