詳解Oracle解鎖相關(guān)過(guò)程
在這里我們將介紹Oracle解鎖的步驟,包括具體的代碼以及操作,希望本文能為大家在Oracle數(shù)據(jù)庫(kù)管理工作中,有所幫助。
- from v$locked_object t1,v$session t2
- where t1.session_id=t2.sid order by t2.logon_time;
解鎖
- --alter system kill session 'sid,serial'
- alter system kill session '146,21177';
鎖表 --lock table tb_name in 模式
Null空值
- Null and false ->false
- Null and true-> null
- Null or false ->null
- Null or true->true
組函數(shù)忽略空值
空值排序時(shí)大于任何值,且不能被索引。
- Merge into
- MERGE [hint] INTO [schema .] table [t_alias] USING [schema .]
- { table | view | subquery } [t_alias] ON ( condition )
- WHEN MATCHED THEN merge_update_clause
- WHEN NOT MATCHED THEN merge_insert_clause;
例:
- merge into acct a
- using subs b
- on (a.msid = b.msid)
- when MATCHED then
- update set a.areacode = b.areacode
- when NOT MATCHED then
- insert (msid, bill_month, areacode) values (b.msid, '200702', b.areacode)
10g中增強(qiáng)一:條件操作 where
WHEN MATCHED THEN ...where ...
10g中增強(qiáng)二:刪除操作
- An optional delete where clause can be used to clean up after a merge operation. Only those rows which match both the ON clause and the DELETE WHERE clause are deleted
- merge into acct a
- using subs b on (a.msid=b.msid)
- when MATCHED then
- update set a.areacode=b.areacode
- delete where (b.ms_type!=0);
其中滿(mǎn)足 (b.ms_type!=0) 的將被deleted
With 語(yǔ)句
with語(yǔ)句只能用在select語(yǔ)句中,update和delete不支持
- with summary as(
- select dname, sum(sal) as dept_total
- from ct_emp, ct_dept
- where ct_emp.deptno = ct_dept.deptno
- group by dname)
- select dname, dept_total
- from summary
- where dept_total > (select sum(dept_total) * 1 / 3 from summary);
臨時(shí)表temporary table
1、臨時(shí)表需要先創(chuàng)建,不建議在運(yùn)行時(shí)使用DDL語(yǔ)句創(chuàng)建
2、臨時(shí)表可以看作是一張普通的物理表, 但它的數(shù)據(jù)是會(huì)話(huà)隔離的
區(qū)別之處:
l 向表中插入數(shù)據(jù)只在會(huì)話(huà)或事務(wù)期間存在
l 表中的數(shù)據(jù)只對(duì)插入數(shù)據(jù)的會(huì)話(huà)是可見(jiàn)的
l 可用ON COMMIT指導(dǎo)定數(shù)據(jù)是會(huì)話(huà)專(zhuān)用還是事務(wù)專(zhuān)用
- create global temporary tablename(column list)
- on commit preserve rows; --提交保留數(shù)據(jù)會(huì)話(huà)臨時(shí)表
- on commit delete rows; --提交刪除數(shù)據(jù) 事務(wù)臨時(shí)表
oracle的臨時(shí)表和sql server不一樣,在使用完成以后,oracle臨時(shí)表中的紀(jì)錄可以被定義為自動(dòng)刪除(分session方式和transaction方式),而表結(jié)構(gòu)不會(huì)被自動(dòng)刪除;sql server中的臨時(shí)表在使用后會(huì)被完全刪除。
建議:不得已的情況下(比較復(fù)雜的數(shù)據(jù)處理)才使用臨時(shí)表,否則盡可能使用子查詢(xún)代替或使用游標(biāo)。
NVL,NVL2區(qū)別及NULLIF 的使用
| NVL(expr1, expr2):expr1為NULL,返回expr2;不為NULL,返回expr1。
| NVL2 (expr1, expr2, expr3) :xpr1不為NULL,返回expr2;為NULL,返回expr3。expr2和expr3類(lèi)型不同的話(huà),expr3會(huì)轉(zhuǎn)換為expr2的類(lèi)型
| NULLIF (expr1, expr2):相等返回NULL,不等返回expr1
【編輯推薦】