與date操作關系最大的就是兩個轉換函數
to_date() 作用將字符類型按一定格式轉化為日期類型
具體用法:to_date(
如;to_date(
多種日期格式
YYYY
YYY
MM
MONTH
MON
WW
D
DD
DDD
DAY
HH
HH
MI
SS
SSSS
to_char():將日期轉按一定格式換成字符類型
SQL> select to_char(sysdate
TIME
即把當前時間按yyyy
在oracle中處理日期大全
TO_DATE格式
Day:
dd number
dy abbreviated fri
day spelled out friday
ddspth spelled out
Month:
mm number
mon abbreviated mar
month spelled out march
Year:
yy two digits
yyyy four digits
[ZT]日期和??函???
日期和字符轉換函數用法(to_date
select to_char( to_date(
顯示Two Hundred Twenty
求某天是星期幾
select to_char(to_date(
星期一
select
to_char(to_date(
= American
monday
設置日期語言
ALTER SESSION SET NLS_DATE_LANGUAGE=
也可以這樣
TO_DATE (
兩個日期間的天數
select floor(sysdate
select id
UNION
select
注意要用TO_DATE(null)
a_date between to_date(
to_date(
那麼
所以
輸入的格式要看你安裝的ORACLE字符集的類型
alter system set NLS_DATE_LANGUAGE = American
alter session set NLS_DATE_LANGUAGE = American
或者在to_date中寫
select
to_char(to_date(
= American
注意我這只是舉了NLS_DATE_LANGUAGE
可查看
select * from nls_session_parameters
select * from V$NLS_PARAMETERS
select count(*)
from ( select rownum
from all_objects
where rownum <= to_date(
)
where to_char( to_date(
not
in (
查找
在前後分別調用DBMS_UTILITY
select months_between(to_date(
to_date(
select months_between(to_date(
to_date(
Next_day(date
Monday
Mon
select to_char(sysdate
注意
可以建立一個函數來處理這個問題
create or replace function sys_date return date is
begin
return sysdate;
end;
select to_char(sys_date
獲得小時數
SELECT EXTRACT(HOUR FROM TIMESTAMP
SQL> select sysdate
SYSDATE TO_CHAR(SYSDATE
SQL> select sysdate
SYSDATE TO_CHAR(SYSDATE
獲取年月日與此類似
年月日的處理
select older_date
newer_date
years
months
abs(
trunc(
newer_date
add_months( older_date
)
) days
from ( select
trunc(months_between( newer_date
mod(trunc(months_between( newer_date
newer_date
older_date
from ( select hiredate older_date
add_months(hiredate
from emp )
)
處理月份天數不定的辦法
select to_char(add_months(last_day(sysdate) +
找出今年的天數
select add_months(trunc(sysdate
from dual
閏年的處理方法
to_char( last_day( to_date(
如果是
yyyy與rrrr的區別
yyyy
rrrr
yyyy
rrrr
select to_char( NEW_TIME( sysdate
hh:mi:ss
from dual;
Select TO_DATE(FLOOR(TO_CHAR(sysdate
from dual
SSSSS表示
一年的第幾天
select TO_CHAR(SYSDATE
select
Days
A
TRUNC(A*
TRUNC(A*
TRUNC(A*
TRUNC(A*
from
(
select
trunc(sysdate) Days
sysdate
from dual
)
select * from tabname
order by decode(mode
//
floor((date
floor((date
mod(mod(date
next_day(sysdate
日 一 二 三 四 五 六
oracle中有很多關於日期的函數
在oracle中有很多關於日期的函數
date_value:=add_months(date_value
例
SQL> select add_months(sysdate
Next Year
SQL> select add_months(sysdate
Last Year
SQL>
date_value:=current_date
SQL> column sessiontimezone for a
SQL> select sessiontimezone
SESSIONTIMEZONE CURRENT_DA
+
SQL> alter session set time_zone=
會話已更改
SQL> select sessiontimezone
SESSIONTIMEZONE CURRENT_TIMESTAMP
SQL>
timestamp_with_time_zone_value:=current_timestamp([timestamp_precision])
SQL> column sessiontimezone for a
SQL> column current_timestamp format a
SQL> select sessiontimezone
SESSIONTIMEZONE CURRENT_TIMESTAMP
+
SQL> alter session set time_zone=
會話已更改
SQL> select sessiontimezone
SESSIONTIMEZONE CURRENT_TIMESTAMP
SQL>
varchar_value:=dbtimezone
SQL> select dbtimezone from dual;
DBTIME
SQL>
date_value:=extract(date_field from [datetime_value|interval_value])
SQL> select extract(month from sysdate)
This Month
SQL> select extract(year from add_months(sysdate
dual;
SQL>
date_value:=last_day(date_value)
SQL> select last_day(date
Leap Yr?
SQL> select last_day(sysdate)
Last day o
SQL>
timestamp_value:=localtimestamp
SQL> column localtimestamp format a
SQL> select localtimestamp from dual;
LOCALTIMESTAMP
下午
SQL> select localtimestamp
LOCALTIMESTAMP CURRENT_TIMESTAMP
下午
SQL> alter session set time_zone=
會話已更改
SQL> select localtimestamp
LOCALTIMESTAMP SYSDATE
下午
SQL>
number_value:=months_between(date_value
SQL> select months_between(sysdate
MONTHS_BETWEEN(SYSDATE
SQL> select months_between(sysdate
MONTHS_BETWEEN(SYSDATE
SQL>
?周相?日期函?
select trunc(decode(ww
to_date(yy ||
from (select substr(
from dual)
select
trunc(to_date(substr(
first_day from dual
select min(v_date) from
(select (to_date(
from all_tables
where rownum <
where to_char(v_date
select trunc(decode(ww
to_date(yy ||
first_day
from (select substr(
from dual)
select
trunc(to_date(substr(
last_day from dual
select max(v_date) from
(select (to_date(
from all_tables
where rownum <
where to_char(v_date
select min_date
(select to_date(substr(
min_date
from all_tables
where rownum <=
decode(mod(to_number(substr(
union
select to_date(substr(
decode(mod(to_number(substr(
min_date
from all_tables
where rownum <=
union
select to_date(substr(
min_date
from all_tables
where rownum <=
)
where to_char(min_date
From:http://tw.wingwit.com/Article/program/Oracle/201311/18444.html