Oracle中對時間操作的一些總結
sysdate+(
sysdate+
sysdate+
sysdate+
add_months(sysdate
add_months(sysdate
上月末的日期
本月的最後一秒
本周星期一的日期
年初至今的天數
今天是今年的第幾周 :select to_char(sysdate
今天是本月的第幾周:SELECT TO_CHAR(SYSDATE
本月的天數
SELECT to_char(last_day(SYSDATE)
今年的天數
select add_months(trunc(sysdate
下個星期一的日期
SELECT Next_day(SYSDATE
============================================
create table t(s date
alter session set nls_date_format =
insert into t values(
insert into t values(
insert into t values(
insert into t values(
insert into t values(
insert into t values(
select s
trunc((e
from t;
引此
================================================================================
判斷當前時間是上午下午還是晚上
SELECT CASE
WHEN to_number(to_char(SYSDATE
WHEN to_number(to_char(SYSDATE
WHEN to_number(to_char(SYSDATE
END
FROM dual;
================================================================================
Oracle 中的一些處理日期
將數字轉換為任意時間格式
SELECT to_char(floor(TRUNC(
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
日期和字符轉換函數用法(to_date
select to_char( to_date(
顯示Two Hundred Twenty
求某天是星期幾
select to_char(to_date(
星期一
select to_char(to_date(
monday
設置日期語言
ALTER SESSION SET NLS_DATE_LANGUAGE=
也可以這樣
TO_DATE (
兩個日期間的天數
select floor(sysdate
select id
UNION
select
注意要用TO_DATE(null)
a_date between to_date(
那麼
所以
輸入的格式要看你安裝的ORACLE字符集的類型
alter system set NLS_DATE_LANGUAGE = American
alter session set NLS_DATE_LANGUAGE = American
或者在to_date中寫
select to_char(to_date(
注意我這只是舉了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
閏年的處理方法
to_char( last_day( to_date(
如果是
yyyy與rrrr的區別
yyyy
rrrr
yyyy
rrrr
select to_char( NEW_TIME( sysdate
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
日 一 二 三 四 五 六
select (sysdate
日期 返回的是天 然後 轉換為ss
轉此
將數字轉換為任意時間格式
SELECT to_char(floor(TRUNC(
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
日期和字符轉換函數用法(to_date
select to_char( to_date(
顯示Two Hundred Twenty
求某天是星期幾
select to_char(to_date(
星期一
select to_char(to_date(
monday
設置日期語言
ALTER SESSION SET NLS_DATE_LANGUAGE=
也可以這樣
TO_DATE (
兩個日期間的天數
select floor(sysdate
select id
UNION
select
注意要用TO_DATE(null)
a_date between to_date(
那麼
所以
輸入的格式要看你安裝的ORACLE字符集的類型
alter system set NLS_DATE_LANGUAGE = American
alter session set NLS_DATE_LANGUAGE = American
或者在to_date中寫
select to_char(to_date(
注意我這只是舉了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;
From:http://tw.wingwit.com/Article/program/Oracle/201311/16736.html