1.關於Union的知識sql
select 11 from dual union select 11 from dual
和數據庫
select 11 from dual union all select 11 from dual
有區別,Union的做用是合併查詢結果 All保留重複行oracle
2. 關於Order By的知識函數
2.1 select t.*, t.rowid from users t order by 1,2
--按照列號排序
2.2 select t.*, t.rowid from users t order by t.name nulls first
-- 該字段空值排前面
select t.*, t.rowid from users t order by t.name nulls last
-- 該字段空值排後面
2.3 select t.*, t.rowid from users t where t.name in('admin','test2','測試')order by instr('admin,test2,測試',t.name)
--按in順序排序
2.3.1 select t.*, t.rowid from users t order by instr('admin,test2,測試',t.name) desc
--按in順序排序 ps:排在最底部 各位能夠按需求對 instr裏面的值進行調整
3. 關於Base64位數據庫加密解密的知識測試
select utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw('MTEuMg=='))) as "Base64解碼後數據" from dual --解密 結果11.2
select utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(11.2))) from dual -- 加密 結果 MTEuMg==
4. Oracle Mod的用法 取n之內被m整除的數加密
select t.rnum from (SELECT rownum rnum FROM ALL_OBJECTS WHERE ROWNUM <= 10 ) t where mod(t.rnum,3)=0 ; --10之內被3整除的數 結果 3,6,9 select sum(t.rnum) as total_sum from (SELECT rownum rnum FROM ALL_OBJECTS WHERE ROWNUM <= 10 ) t where mod(t.rnum,3)=0 ; --10之內被3整除的數的和 結果 18
5.Oracle Decode的用法spa
select decode(AA,'11','數據是11','22','數據是22','其餘數據') as "數據結果" from( select 11 as AA from dual union all select 22 from dual union all select 221 from dual union all select 333 from dual )
6.Oracle 的start with 用法code
select t.* from sys_tree t where t.isdel=1 start with t.code='100' connect by prior t.id = t.pid order by t.orderno --查詢全部的子節點 select t.* from sys_tree t where t.isdel=1 start with t.code='100' connect by prior t.pid = t.id order by t.orderno --查詢全部的父節點
7.oracle Update Select語句blog
update suppliers a set (supplier_class,status)=(select b.name,b.value from tmptmp1 b where a.code = b.id)
8.oracle行轉列之wmsys.WM_CONCAT()方法排序
select t.ID, t.Name from TestTab t;
A2 T10
A3 T12
A2 1sd
A1 123
A1 ssss
A3 1234
咱們經過 10g 所提供的 WMSYS.WM_CONCAT 函數便可以完成 行轉列的效果 select t.ID, WMSYS.WM_CONCAT(t.Name) NAME From TestTab t GROUP BY t.ID;