Oracle經常使用sql語句。

最近工做中遇到了一些與oracle相關的問題,稍微整理一些工做中用到的SQL語句

時間相關

--查詢距當前時間十分鐘內的數據
select sysdate -interval '10' minute as time from dual;

--查詢距當前時間十天內的數據
select sysdate -interval '10' day as time from dual;

--查詢年月日 時分秒
select to_char(sysdate,'yyyy-MM-dd HH24:mm:ss') as time from dual

數值處理

--小數點前的0不顯示
select to_char(0.58740,'fm99990.0099') from dual

基本語法

--case when then 語句
 select
    (case a.cjrlx 
               when '1' then '0'
               when '2' then '1'
               when '3' then '2'
    end) as pasType --伺機人類型
        from kh_khddcjr a

基本函數

--decode函數的基本用法
    --M:男  F:女
    --至關於 if--else if--else 語句,若是性別是M,返回1,若是是F,返回2,若是還有其它的,能夠接着寫下去。感受和case--when 挺像。
    select decode(k.xb,'M','1','F','2') as xb from  user k;

    
    --NVL函數
    --主要做用是從兩個表達式返回一個非 null 值。
    --若是eExpression1的值是null,就返回eExpression2的值
    select NVL(k.xcdh,'000') as scdh from user k

數據處理

--查詢某個字段是否有重複的
    select g.wxid,count(*) from BASE_GETWXID g group by g.wxid having count(*) > 1
相關文章
相關標籤/搜索