oracle数据库应用(二)

--创建表空间
create tablespace ts01
datafile 'f:/table/ts02.dbf' size 50m
autoextend on
--删除表空间
drop tablespace ts
--调整表空间的大小(方法一、更改数据文件的大小)
alter database datafile 'f:/table/ts02.dbf' resize 100m
--调整表空间的大小(方法二、向表空间里添加数据文件)
alter tablespace ts01 add datafile 'f:/table/ts03.dbf' size 20m autoextend on
--更改表空间的只读状态
alter tablespace ts01 readonly
--表空间的删除(删除数据,保留表空间的结构)
drop tablespace ts01 including contents;

--创建用户
create user root
identified by root;
--创建权限
grant create session to root;--赋予连接数据库的权限
grant create table to root;--赋予创建表的权限
grant create view to root;--赋予创建视图的权限
--分配权限角色
grant connect,resource to root;
--撤销权限
revoke connect,resource from root;
--删除用户
drop user user_name;
--创建序列
create sequence emp_id(
  start with 1;
  increment by 1;
  maxvalue 9999;
  minvalue 1;
  nocycle --在达到最大值后停止生成下一个值 如果设置为cycle(达到最大值之后会从开始值循环增加)
  cache 10;--指定内存中预先分配的序号数 
);
--nextval 返回序列的下一个值
select emp_id.nextval from dual;
--currval 返回序列的当前值
select emp_id.currval from dual;
--ALTER SEQUENCE语句修改序列(不能更改序列的START WITH参数)
alter sequence emp_id maxvalue 5000 cycle;
--删除序列
drop sequence emp_id;
--私有同义词(只能被当前的模式用户访问)
create synonym e for system.emp
replace synonym ee for system.emp
drop synonym e;
--公有同义词(可以被所有数据库用户访问)
create public synonym e for system.emp
replace public synonym e from system.emp
dop public synonym e;

--创建B树索引
create index index_id on goods(gid);
--创建反向索引
create index index_id on goods(gid) reverse;
--创建位图索引(位图索引不直接存储ROWID,而是存储字节位到ROWID的映射)
create bitmap index index_id on goods(gid);
--删除索引
drop index index_id;
--重建索引
alter index index_id rebuild noreverse;
-------------范围表分区-----------------
--创建表分区(和表创建一起创建)
create table goods(
   gid number primary key,
   gname varchar2(20),
   price number
)
partition by range(price)
(
   partition p1 values less than(20),
   partition p1 values less than(30),
   partition p1 values less than(60),
   partition pn values less than(maxvalue),
)
--通过表分区查看数据
select * from goods partition(p2);
--删除某个分区下的数据
delete from goods partition(p3);
-----------------间隔表分区---------------------
--创建间隔表分区(日期)
create table goods(
   gid number primary key,
   gname varchar2(20),
   price number,
   createDate Date not null
)
partition by range(createDate) interval(NUMTOYMINTERVAL(n, 'month'))
(
   partition P1 values less than(to_date('2018-5-5','yyyy-MM-dd'))
)
--插入数据
insert into goods(1,'a',10,to_date('2018-1-1'));

--视图操作
create view goods_view as select * from goods where price<30
replace view goods_view as select * from goods where price<30
select * from goods_view;
drop view goods_view;

 

posted @ 2018-07-08 11:43  刚刚睡醒  阅读(217)  评论(0编辑  收藏  举报