oracle总结1

上传人:aa****6 文档编号:38288781 上传时间:2018-04-29 格式:PDF 页数:24 大小:202.17KB
返回 下载 相关 举报
oracle总结1_第1页
第1页 / 共24页
oracle总结1_第2页
第2页 / 共24页
oracle总结1_第3页
第3页 / 共24页
oracle总结1_第4页
第4页 / 共24页
oracle总结1_第5页
第5页 / 共24页
点击查看更多>>
资源描述

《oracle总结1》由会员分享,可在线阅读,更多相关《oracle总结1(24页珍藏版)》请在金锄头文库上搜索。

1、创建一个用户并为其指定表空间 创建表 空 间:create tablespace tsb datafile c:aaa.aaa size 10m; 创 建 用 户:create user deb identified by tibi; 赋权限:grant unlock to deb; grant connect to deb; grant dba to deb; grant all on aa to scott; 修改用户表空间:alter user deb default tablespace tsb; - 自动生成报表 打开池:spool c:aaa.txt; 查询语句:select *

2、from aa; 关闭池:spool off; - 查看 表结构:desc table_name; select column_name,data_type from user_tab_columns where table_name=? 表:select * from user_all_tables; - 用户 修改密码:alter user deb identified by tibire; 删除用户:drop user deb; 查看用户:show user;select user from dual;select user from aa; 操纵表 创建:create table aa

3、(a int);-表名不能超过三十个字符 删除所有行:truncate table aa; 修改列:alter table aa modify (a varchar2(20);-列必须为空 添加列:alter table aa add(b varchar(20); 删除列:alter table aa drop column b; 查看表结构:desc aa; 删除表:drop table aa; 临时表:create global temporary table mm(a varchar(20) on commit delete rows; -事务完成后自动删除行,行为动态分配 :creat

4、e global temporary table mm(a varchar(20) preserve rows; -会话期间表一直存在 - 集合操作 Union:select a from aa union select b from bb;-重复行只显示第一个表的数据 Union all:select a from aa union all select b from bb; -显示全部数据 Intersect:select a from aa intersect select b from bb; -显示两表相同记录 Minus:select a from aa minus select

5、b from bb; -显示后表没有的前表的记录 |:select aaa | bbbb mk from dual;-显示 aaabbbb 操作符优先级:算术连接比较notandor -事务控制 保存标记:savepoint t; 撤消指定操作:rollback to savepoint t; 撤上次 commit 后 :rollback; 赋权限:grant select,update on aa to scott;/ grant update(a) on aa to scott; 撤消权限:revoke select,update on aa fromscott; 锁 行级锁:select

6、 * from aa for update; :delete from deb.aa where a=aa;-用户 SYS 此时已不能删除此行 :drop table deb.aa;-此时表也不能移除 :select * from aa for update wait 5;-此请求资源忙时,5 秒抛出错误 表级锁(共享锁) :lock table aa in share mode;-仅允许其它用户查询 (共享更新锁):lock table aa in share update mode;-仅禁止其它用户更新正在更新的行 (排它锁):lock table aa in exclusive mode

7、; -一个资源同一时间只允许一个用户放 置排它锁,其它与共享锁类似 (nowait):lock table aa in exclusive mode not wait;-防止其它用户无限的等待 (死锁):oracle 自动检测,并中止其中之一来保证事务的进行 - 表分区 (范围分区) :create tablespace tpa datafile c:mm.mm size 3m; create tablespace tpb datafile c:mm.mm size 3m; create table tc(a int)partition by range(a) ( partition pre

8、values less than(20) tablespace tpa, partition prf values less than(maxvalue) tablespace tpb ) select * from tc partition(pre); select * from tc partition(prf); 在 DATE 类型中:less than(TO_DATE(1999-04-05,yyyy-mm-dd) (散列分区) :create table td(a int) partition by hash(a) ( partition pa tablespace tpa, part

9、ition pa tablespace tpb ) (复合分区):create table tb(a int,b int) partition by range(a) subpartition by hash(b) ( partition pa values less than(10) tablespace tpa ( subpartition paa tablespace tpc, subpartition pab tablespace tpd ),partition pb values less than(maxvalue) tablespace tpb ( subpartition pb

10、a tablespace tpc, subpartition pbb tablespace tpd ) ) (列表分区):create table te(a int) partition by list(a) ( partition aa values(1,2) tablespace tpa, partition bb values(3,4) tablespace tpb ); (维护分区):移动分区 alter table te move partition aa tablespace tpp; -移到新的表空间 添加分区 alter table te add partition aa va

11、lues less than(4) tablespace tpa; 删除分区 alter table te drop partition aa; 结合分区 alter table td coalesce partition ; -仅用于散列分区 截断分区 alter table td truncate partition aa; 拆分分区 alter table ta pslit partition aa at(15) into (partition kk tablespace tpa,partition jj tablespace mk) -15 放到后分区 交换分区 alter table

12、 td exchange partition aa with table te;-当 te 表的 数据符全分区 aa 的边界时才会发生交换数据 合并分区 alter table td merge partitions a,b into partition e; - 同义词 (于 scott 用户中):create synonym aa for deb.aa;公有同义词由 DBA 创建,私有同义词则 是非 DBA 创建,且只能在单个用户中用 (删除同义词):drop synonym aa; - 序列 (创建序列):create sequence sq increment by 2-正数则为升序,

13、负数为降序,步值在这里为 2 start with 10-初始值 minvalue 10 nominvalue-升序最小值是 1,降序最小值是-10 的 26 次方 maxvalue 100 nomaxvalue-升序最大值是 10 的 27 次方,降序最大值是-1 cycle-当达到最大值或最小值时,重新生成 nocycle-不重新生成 cache-预先生成一组数据,加快速度 cache-不预先生成数据 (访问序列):select sq.nextval from dual;-必须先 next 为其初始化值 select sq.currval from dual; (修改序列):-不能修改 start with 值,其余均可 (删除序列):drop sequence sq;- 视图 (创建视图):create or replace force/noforce view v as select * from aa; (分区视图):create or replace view vw as select * from aa union all select * from bb; (删除视图):drop view vw -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号