首页 > 代码库 > 数据库知识(主要基于Oracle,Sql可参考)

数据库知识(主要基于Oracle,Sql可参考)

1.关于Union的知识

select 11 from dualunion select 11 from dual

select 11 from dualunion allselect 11 from dual

有区别,Union的作用是合并查询结果  All保留重复行

 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 inadmin,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的用法

select decode(AA,11,数据是11,22,数据是22,其他数据) as "数据结果"from(select 11 as AA from dualunion allselect 22 from dualunion allselect 221 from dualunion allselect 333 from dual)

 6.Oracle 的start with 用法

select t.* from sys_tree t where t.isdel=1start with t.code=100connect by prior t.id = t.pidorder by t.orderno--查询所有的子节点                        select t.* from sys_tree t where t.isdel=1start with t.code=100connect by prior t.pid = t.idorder by t.orderno--查询所有的父节点

 

数据库知识(主要基于Oracle,Sql可参考)