單行函式(日期函式)

2022-05-26 23:21:10 字數 2478 閱讀 5745

oracle 預設的日期格式為 dd-mon-yyyy     select sysdate from dual;

d            表示2位數的日

mon/month    表示月份,如:6月

mm            表示2位數的月,如:06

yyyy        表示4位數的年份

hh24        表示24小時

hh            表示12小時

mi            表示分鐘

ss            表示秒

fm            表示去掉前面的0,如:fm 06,值為6

day            表示星期幾

months_between ( date1,date 2)         :2個日期之前月數

add_months(date,n)     這個date日期 加上n個月   n可為負數

next_day(date,'星期幾')          date  下個星期幾

last_day(date)                         date 當月的月底日期

補充:修改當前會話語言環境:

alter session set nls_language = 'american';//改為英文

alter session set nls_language = 'simplified chinese';//改為簡體中文

修改當前會話日期格式:

alter session set nls_date_formate='yyyy-mm-dd hh24:mi:ss';//改為年月日時分秒

轉換函式

to_number   字元轉換成數字  select to_number('9837492.563','999999999.999') from dual         

to_date  字元轉換成日期         select to_date('2009-10-3 15:10:23','yyyy-mm-dd hh24:mi:ss') from dual

to_char:日期/數字 轉換成 字元            

select to_char (sysdate,'yyyy-mm-dd hh24:mi:ss')     from dual    

select to_char(9837492,'$999,999,999.99') from dual            

select to_char(9837492.563,'999999999.99') from dual                  轉換成字串    字串可比數字少一位  結果也少一位                                 字串少一位可以

extract(年|月|日   from   date)   得到 年|月|日    :提取

selectextract(yearfromsysdate)

,extract(monthfromsyadate)

,extract(dayfromsyadate

,extract(minutefromsyadate

,extract(secondfromsyadate

,extract(timezone_hourfromsyadate)  

,extract(timezone_minutefromsyadate)  

,extract(timezone_regionfromsyadate)   

,extract(timezone_abbrfromsyadate)   

fromdual

4.把數字格式化為字元竄的時候可以用一些符號

9 代表任意資料

l 代表本地的貨幣符號

$ 代表美元

0 代表0

. 代表.

, 代表,

oracle 單行函式 日期函式

1.按天加 2.month between準確計算日期相差月份 select hire date,trunc sysdate hire date as 日期相減後,3.add months 月份新增 next day 得到下週某天的日期 last day 得到某月最後一天 select add mo...

oracle中單行函式日期時間函式總結

表中存在偽列 sysdate,systimestamp 偽列存在但是不顯示 select sysdate from dual select systimestamp from dual 日期計算公式 日期 天數 日期 日期 天數 日期 日期 日期 天數 函式編號 函式描述 函式使用例項 1返回 日期...

8 單行函式之數學函式 日期函式 其他函式

1 round 四捨五入 select round 1.65 select round 1.5 不管正數負數,先把絕對值四捨五入了,再新增正負號 select round 1.567,2 小數點後保留兩位進行四捨五入2 ceil 向上取整 返回 該引數的最小整數 select ceil 0.0021...