Oracle学习笔记大全.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《Oracle学习笔记大全.doc》由会员分享,可在线阅读,更多相关《Oracle学习笔记大全.doc(92页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、一:sql语句1.增加主键alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN);指定表空间alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN) using index tablespace TABLE_SPACE_NAME;2.增加外键alter table TABLE_NAME add constraint FK_NAME foreign key (TABLE_COLUMN) references KEY_
2、TABLE_NAME;3.使主键或外键失效、生效alter table TABLE_NAME disable(enable) constraint KEY_NAME;4、查看各种约束select constraint_name,table_name,constraint_type,status from user_constraints;select constraint_name, constraint_type,search_condition, r_constraint_name from user_constraints where table_name = upper(&table_
3、name)select c.constraint_name,c.constraint_type,cc.column_name from user_constraints c,user_cons_columns ccwhere c.owner = upper(&table_owner) and c.table_name = upper(&table_name)and c.owner = cc.owner and c.constraint_name = cc.constraint_nameorder by cc.position; 5、删除主键或外键alter table TABLE_NAME d
4、rop constraint KEY_NAME;6、建外键单字段时:create table 表名 (col1 char(8),cno char(4) REFERENCE course);多个字段时,在最后加上 Foreign Key (字段名) REFERENCE 表名(字段)IXDBA.NET社区论坛连带删除选项 (on delete cascade当指定时,如果父表中的记录被删除,则依赖于父表的记录也被删除REFERENCE 表名() on delete cascade;7、删除带约束的表Drop table 表名 cascade constraints;8:索引管理.creating
5、function-based indexes sql create index summit.item_quantity on summit.item(quantity-quantity_shipped); .create a B-tree index sql create unique index index_name on table_name(column,. asc/desc) tablespace sql tablespace_name pctfree integer initrans integer maxtrans integer sql logging | nologging
6、nosort storage(initial 200k next 200k pctincrease 0 sql maxextents 50); .pctfree(index)=(maximum number of rows-initial number of rows)*100/maximum number of rows .creating reverse key indexes sql create unique index xay_id on xay(a) reverse pctfree 30 storage(initial 200k sql next 200k pctincrease
7、0 maxextents 50) tablespace indx; .create bitmap index sql create bitmap index xay_id on xay(a) pctfree 30 storage( initial 200k next 200k sql pctincrease 0 maxextents 50) tablespace indx; .change storage parameter of index sql alter index xay_id storage (next 400k maxextents 100); 7.allocating inde
8、x space sql alter index xay_id allocate extent(size 200k datafile c:/oracle/index.dbf); .alter index xay_id deallocate unused; 、查看索引SQLselect index_name,index_type,table_name from user_indexes order by table_name;、查看索引被索引的字段SQLselect * from user_ind_columns where index_name=upper(&index_name);11、创建序
9、列select * from user_sequences;create sequence SEQ_NAME start with 1000 maxvalue 1000 increment by 1;alter sequence SEQ_NAME minvalue 50 maxvalue 100;12、删除重复行update a set aa=null where aa is not null;delete from a where rowid!=(select max(rowid) from a b where a.aa=b.aa);13、删除同其他表相同的行delete from a wh
10、ere exits(select X from b where b.no=a.no);或delete from a where no in (select no from b);14、查询从多少行到多少行的记录(可以用在web开发中的分页显示)select * from ( select rownum row_id,b.* from (select a.* from sys_oper a) b )where row_id between 15 and 2015、对公共授予访问权grant select on 表名 to public;create public synonym 同义词名 for
11、 表名;16、填加注释comment on table 表名 is 注释;comment on column 表名.列名 is 注释;17、分布式数据库,创建数据库链路create public database link LINKNAME connect to USERNAME identified by PASSWORDusing CONNECT_STRING可以在服务器端,也可以在客户端建立,但必须注意,两台服务器之间数据库必须可以互访,必须各有各自的别名数据库18、查看数据库链路select * from all_db_links;select * from user_db_links
12、;查询 select * from TABLENAMEDBLNKNAME;创建远程数据库同义词create synonym for TABLENAMEDBLNKNAME;操纵远程数据库记录insert into TABLENAMEDBLNKNAME (a,b) values (va,vb);update TABLENAMEDBLNKNAME set a=this;delete from TABLENAMEDBLNKNAME;怎样执行远程的内嵌过程beginotherdbproto_html(参数);end;19、数据库链路用户密码有特殊字符的时候,可以用双引号把密码引起来create publ
13、ic database link dblink1 connect to db1 identified by 123*456 using db1120.oracle8中扩充了group by rollup和cube的操作。有时候省了你好多功夫的。下面的语句可以进行总计select region_code,count(*) from aicbs.acc_woff_notifygroup by rollup(region_code); 对第1个字段小计,最后合计select region_code,write_status,count(*) from aicbs.acc_woff_notifygro
14、up by rollup(region_code,write_status);-570 0 3570 1 2570 5 -此处小计了570的记录571 0 10571 1 2571 12 -此处小计了571的记录.100 -此处有总计 复合rollup表达式,只做总计select region_code,write_status,count(*) from aicbs.acc_woff_notifygroup by rollup(region_code,write_status); 对第1个字段小计,再对第2个字段小计,最后合计select region_code,write_status,c
15、ount(*) from aicbs.acc_woff_notifygroup by cube(region_code,write_status);-100 -此处有总计0 60 -对write_status0的小计1 39 -对write_status1的小计3 1 -对write_status3的小计570 5 -此处小计了570的记录570 0 3570 1 2571 12 -此处小计了571的记录571 0 10571 1 2. 复合cube表达式,只做总计select region_code,write_status,count(*) from aicbs.acc_woff_noti
16、fygroup by cube(region_code,write_status);下面的语句可以按照rollup不同的字段进行小计select region_code,write_status,count(*) from aicbs.acc_woff_notifygroup by region_code,rollup(write_status);21.查询view的创建语句sqlset long 1000sqlselect * from user_views where view_name=MY_VIEW_NAME;orsqlselect * from all_views where vie
17、w_name=MY_VIEW_NAME;22、去除数据库中特殊字符.字符串字段中含有,如果用来组合sql语句,会造成语句不准确。比如:replace(f1,).字符串字段中含有t n,如果用来在c或者c程序中输出到文件,格式无法保证。比如:replace(f2,t,).清除换行和回车比如: replace(f2,chr(13)|chr(10),)23、如何在字符串里加回车或者tab键 在sqlplus中执行sqlselect UserId=|chr(10)|AccId=13431|chr(9)|AccId2=11111 from dual;24、树形查询create table zj(bm n
18、umber(8),bmmc varchar2(20),sjbm number(8)insert into zj values(1,aaa,0)insert into zj values(11,aaa1,1)insert into zj values(12,aaa2,1)insert into zj values(111,aaa11,11)insert into zj values(112,aaa12,11)insert into zj values(113,aaa13,11)insert into zj values(121,aaa21,12)insert into zj values(122
19、,aaa22,12)insert into zj values(123,aaa23,12)-select bm,bmmc,sjbm,levelfrom zjstart with sjbm=0connect by prior bm = sjbm或者select bm,bmmc,sjbm,levelfrom zjstart with sjbm=0connect by sjbm = prior bm 25、快照create snapshot SNAPSHOT_NAME storage (storage parameter)tablespace TABLESPACE_NAMErefresh fastc
20、ompleteforcestart with START_DATE next NEXT_DATEas QUERY;create snapshot snapshot_to_study as select * from TABLE_NAMEto_study;创建角色create role aa identified by aaa;授权 grant create snapshot,alter snapshot to aaa;grant aaa to emp;create snapshot SNAPSHOT_TO_HTML refresh complete start with sysdate nex
21、t sysdate+5/(24*60*60) as select * from ato_html;删除 drop snapshot snap_to_html手工刷新快照,(调用DBMS_SNAPSHOT包中的refresh过程)DBMS_SNAPSHOT.refresh(snapshot_name,refresh_type);beginDBMS_SNAPSHOT.REFRESH(snap_to_html,c);end;对所有快照进行刷新beginDBMS_SNAPSHOT.REFRESH_ALL;end;怎样执行远程的内嵌过程beginotherdbproto_html(参数);end;26、
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Oracle 学习 笔记 大全
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内