常見sql函數(shù)

2018-08-18 15:11 更新

一:decode 語法:DECODE(SEX,'0','男','2','女','3','其他') 無需解釋一看便知。

二:trunc 語法:

  /**************日期********************/
    1.select trunc(sysdate) from dual --2017-08-18 今天的日期為2017-08-18
    2.select trunc(sysdate, 'mm') from dual --2017-08-01 返回當月第一天.
    3.select trunc(sysdate,'yy') from dual --2017-01-01 返回當年第一天
    4.select trunc(sysdate,'dd') from dual --2017-08-18 返回當前年月日
    5.select trunc(sysdate,'yyyy') from dual --2017-01-01 返回當年第一天
    6.select trunc(sysdate,'d') from dual --2017-08-13 (星期天)返回當前星期的第一天
    7.select trunc(sysdate, 'hh') from dual --2017-08-18 17:00:00 當前時間為17:35 
    8.select trunc(sysdate, 'mi') from dual --2017-08-18 17:35:00 TRUNC()函數(shù)沒有秒的精確
    9.select trunc(lase_day(add_months(sysdate,-1))) --獲取系統(tǒng)上月最后一天日期2017-07-31
    /***************數(shù)字********************/
    /*
    TRUNC(number,num_digits) 
    Number 需要截尾取整的數(shù)字。 
    Num_digits 用于指定取整精度的數(shù)字。Num_digits 的默認值為 0。
    TRUNC()函數(shù)截取時不進行四舍五入
    */
    9.select trunc(123.458) from dual --123
    10.select trunc(123.458,0) from dual --123
    11.select trunc(123.458,1) from dual --123.4
    12.select trunc(123.458,-1) from dual --120
    13.select trunc(123.458,-4) from dual --0
    14.select trunc(123.458,4) from dual --123.458
    15.select trunc(123) from dual --123
    16.select trunc(123,1) from dual --123
    17.select trunc(123,-1) from dual --120

三:to_date 語法:TO_DATE('date1'+'00:00:00','yyyy-mm-dd hh24:mi:ss')

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號