当前位置:Gxlcms > 数据库问题 > 数据库知识(主要基于Oracle,Sql可参考)

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

时间:2021-07-01 10:21:17 帮助过:3人阅读

 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 dual
union all
select 22 from dual
union all
select 221 from dual
union all
select 333 from dual
)

 6.Oracle 的start with 用法

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
--查询所有的父节点

 

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

标签:

人气教程排行