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
日期和字符轉換函數用法(to_date
We overwrite NLS_DATE_FORMAT into different formats for the session
SQL> alter session set nls_date_format =
SQL> set pagesize
SQL> set linesize
SQL> select * from nls_session_parameters;
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH
NLS_TIMESTAMP_FORMAT DD
NLS_TIME_TZ_FORMAT HH
NLS_TIMESTAMP_TZ_FORMAT DD
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
specify it in SQL statement:
SQL> select to_date(
SQL> alter session set nls_date_format =
Session altered
SQL> select to_date(
TO_DATE(
SQL> alter session set nls_date_format =
Session altered
SQL> select to_date(
TO_DATE(
When we use TO_CHAR function
SQL> alter session set nls_date_format =
Session altered
SQL> select to_char(sysdate
TO_CHAR(SYSDATE
SQL> alter session set nls_date_format =
Session altered
SQL> select to_char(sysdate
TO_CHAR(SYSDATE
SQL> select to_char(sysdate
TO_CHAR(SYSDATE
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(tr
From:http://tw.wingwit.com/Article/program/Oracle/201311/17738.html