1.交換兩條記錄的屬性值
update tx_ry ry1 set px=(select px from tx_ry where id in (pk1,pk2) and id<>ry1.id) where id in (pk1,pk2);
2.自關(guān)聯(lián)查詢
select mk.*,level from xt_xtmk mk where 1=1 start with mc='附加信息管理' connect by prior id=fid?? --向下查
union
select?mk.*,level from xt_xtmk mk where 1=1 start with mc='附加信息管理' connect by prior fid=id?? --向上查
level是偽列,表示所在層級。
3.pk、uk、fk、idx、unique index創(chuàng)建及區(qū)別
alter table Yj_Yjcllc add constraint PK_Yj_Yjcllc primary key (ID);
alter table Yj_Yjcllc add constraint UK_Yj_Yjcllc unique (sjid,sjspbz);
alter table Yj_Yjcllc add constraint FK_Yj_Yjcllc foreign key (sjid) references YJ_YJJB (ID);
create index idx_Yj_Yjcllc_sjid on Yj_Yjcllc (sjid);? //外鍵建索引能夠提高查詢速度
????? create unique index idx_yj_yjcllc_idbz on yj_yjcllc (sjid,sjspbz);//唯一索引是索引的特例
注意:oracle 會默認(rèn)給pk、uk建索引,但不默認(rèn)給fk建索引,所以需要用戶自己給fk建索引。
pk、uk、fk是約束,可以在user_constraints表中查到;pk索引、uk索引、idx 是索引,可以在user_indexes中查,user_ind_columns 索引列。
uk與唯一索引的區(qū)別:創(chuàng)建pk、uk是系統(tǒng)默認(rèn)在user_constraints表中創(chuàng)建約束,并在user_indexes表中創(chuàng)建唯一索引;
?????????????????????????????唯一索引(unique index)只會在user_indexes表中創(chuàng)建唯一索引,而不會在user_constraints表中創(chuàng)建約束。
4.查看表空間使用情況的SQL語句:??
select a.tablespace_name "表空間名",total 表空間大小,free 表空間剩余大小,??
(total-free) 表空間使用大小, round((total-free)/total,4)*100?? "使用率?? %",
(select file_name from dba_data_files where tablespace_name=a.tablespace_name and rownum<2) "文件名"??
from????
?(select tablespace_name,sum(bytes) free? from dba_free_space group by tablespace_name) a,??
?(select tablespace_name,sum(bytes) total from dba_data_files group by tablespace_name) b??
where a.tablespace_name=b.tablespace_name???
--創(chuàng)建表空間及數(shù)據(jù)文件?
create tablespace iests datafile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORACLE\IES_1.DBF' size 200m reuse autoextend on next 50m;
--給表空間添加數(shù)據(jù)文件
alter tablespace iests add datafile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORACLE\IES_2.DBF' size 200m reuse autoextend on next 50m;
--擴(kuò)展已有數(shù)據(jù)文件的大小
alter database datafile 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORACLE\SYSTEM01.DBF' resize 600M;
5.查詢創(chuàng)建的用戶下的表的記錄數(shù)
select user_id,username,table_name,ies.getfieldvalue('count(1)',table_name,'1=1') cnt
from (select u.user_id,u.username,t.owner||'.'||t.table_name table_name from all_users u,all_tables t where t.owner=u.username and user_id>60 order by user_id,table_name)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
