ORACLE日期型別
ORACLE日期型別
參考:https://blogs.oracle.com/apex/date%2c-timestamp-and-format-masks
資料庫中有4中日期型別:
1、DATE:是最早和使用最廣的日期型別,使用示例如下。
DATE is the oldest and most widely used data type. Though the name is "DATE", it stores also information about the time. Internally, DATE stores year, month, day, hour, minute and second as explicit values. To get the current timestamp as an instance of DATE, use the SYSDATE SQL function.
SQL> alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
SQL> select sysdate, dump(sysdate) as date_bytes from dual;
SYSDATE DATE_BYTES
-------------------- -----------------------------------
2017-11-23 23:41:08 Typ=13 Len=8: 225,7,11,23,23,41,8,0
2、TIMESTAMP:擴充套件了DATA型別,包含了分秒和時區。
TIMESTAMP extends DATE by fractional seconds. Internally, time zone information is also contained, but in order to work with time zones, one of the other two data types, TIMESTAMP WITH TIME ZONE or TIMESTAMP WITH LOCAL TIME ZONE must be used. To get the current timestamp as a TIMESTAMP instance, use the LOCALTIMESTAMP SQL function. As the DUMP result below shows, TIMESTAMP stores year, month, day, hour, minute and second similar to DATE. The other bytes are there for fractional seconds and time zone information. TIMESTAMP instances consume more space on disk than DATE instances, which is natural - they contain more information.
SQL> alter session set nls_timestamp_format='YYYY-MM-DD HH24:MI:SS.FF6';
SQL> select localtimestamp, dump(localtimestamp) ts_bytes from dual;
LOCALTIMESTAMP TS_BYTES
--------------------------- ---------------------------------------------------------------------
2017-11-24 08:45:41.434175 Typ=187 Len=20: 225,7,11,24,8,45,41,0,24,252,224,25,1,0,3,0,127,1,0,0
3、SYSTIMESTAMP顯示時區,SYSTIMESTAMP顯示當前資料庫時區,CURRENT_TIMESTAMP顯示當前會話時區;
TIMESTAMP WITH TIME ZONE allows to explicitly work with time zone information. A time zone can be used to create a TIMESTAMP WITH TIME ZONE instance and it is explicitly contained in the output (use the right format mask). When the output of a TIMESTAMP WITH TIME ZONE value does not contain a time zone, you have incomplete data.
Oracle does not implicitly convert instances of this data type between time zones; this can be done explicitly with the AT TIME ZONE clause. To get the current time as a TIMESTAMP WITH TIME ZONE instance, we can use two functions: SYSTIMESTAMP returns the current time in the database time zone and CURRENT_TIMESTAMP returns it in the current session time zone. The following example uses SYSTIMESTAMP.
SQL> alter session set nls_timestamp_tz_format='YYYY-MM-DD HH24:MI:SS.FF6 TZR';
SQL> select systimestamp as ts_bytes from dual;
SYSTIMESTAMP
----------------------------------
2017-11-23 23:57:04.609608 -08:00
4、本地時區和資料庫時區轉換。TIMESTAMP隱含使用本地時區,預設使用會話時區插入,儲存時預設使用資料庫時區。
TIMESTAMP WITH LOCAL TIME ZONE does not expose the time zone information (to the application, it looks like a TIMESTAMP), but it uses tome zones implicitly: An instance is created without time zone information, the session time zone is assumed. Stored instances are normalized to the database time zone. When the data is retrieved, users see it (again) in the session time zone.
The following example illustrates how TIMESTAMP WITH LOCAL TIME ZONE works: First, a table is created. Then the current time is retrieved and stored into the table ( SYSTIMESTAMP returns TIMESTAMP WITH TIME ZONE, but this is automatically converted to TIMESTAMP WITH LOCAL TIME ZONE ). When the table is then being selected, the returned data changes with the session time zone.
SQL> create table mytimestamps( ts timestamp with local time zone );
SQL> insert into mytimestamps values ( systimestamp );
SQL> alter session set time_zone='Europe/Berlin';
SQL> select * from mytimestamps;
TS
---------------------------------------------------------------------------
2017-11-24 12:55:39.761283
SQL> alter session set time_zone='EST';
SQL> select * from mytimestamps;
TS
---------------------------------------------------------------------------
2017-11-24 06:55:39.761283
Format Masks
Whether we work within an application or a tool like SQL Plus or SQL Developer; whenever we output a DATE or TIMESTAMP instance, we're converting it to VARCHAR2. We can do this explicitly using TO_CHAR or Oracle will do it implcitly. And now NLS format masks kick in - the format mask decides how a DATE is converted to a VARCHAR2 and back. The are defaults for NLS format masks at the database level, we can set them at the session level or we can pass a format mask to the individual TO_CHAR call.
參考:https://blogs.oracle.com/apex/date%2c-timestamp-and-format-masks
資料庫中有4中日期型別:
1、DATE:是最早和使用最廣的日期型別,使用示例如下。
DATE is the oldest and most widely used data type. Though the name is "DATE", it stores also information about the time. Internally, DATE stores year, month, day, hour, minute and second as explicit values. To get the current timestamp as an instance of DATE, use the SYSDATE SQL function.
SQL> alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
SQL> select sysdate, dump(sysdate) as date_bytes from dual;
SYSDATE DATE_BYTES
-------------------- -----------------------------------
2017-11-23 23:41:08 Typ=13 Len=8: 225,7,11,23,23,41,8,0
2、TIMESTAMP:擴充套件了DATA型別,包含了分秒和時區。
TIMESTAMP extends DATE by fractional seconds. Internally, time zone information is also contained, but in order to work with time zones, one of the other two data types, TIMESTAMP WITH TIME ZONE or TIMESTAMP WITH LOCAL TIME ZONE must be used. To get the current timestamp as a TIMESTAMP instance, use the LOCALTIMESTAMP SQL function. As the DUMP result below shows, TIMESTAMP stores year, month, day, hour, minute and second similar to DATE. The other bytes are there for fractional seconds and time zone information. TIMESTAMP instances consume more space on disk than DATE instances, which is natural - they contain more information.
SQL> alter session set nls_timestamp_format='YYYY-MM-DD HH24:MI:SS.FF6';
SQL> select localtimestamp, dump(localtimestamp) ts_bytes from dual;
LOCALTIMESTAMP TS_BYTES
--------------------------- ---------------------------------------------------------------------
2017-11-24 08:45:41.434175 Typ=187 Len=20: 225,7,11,24,8,45,41,0,24,252,224,25,1,0,3,0,127,1,0,0
3、SYSTIMESTAMP顯示時區,SYSTIMESTAMP顯示當前資料庫時區,CURRENT_TIMESTAMP顯示當前會話時區;
TIMESTAMP WITH TIME ZONE allows to explicitly work with time zone information. A time zone can be used to create a TIMESTAMP WITH TIME ZONE instance and it is explicitly contained in the output (use the right format mask). When the output of a TIMESTAMP WITH TIME ZONE value does not contain a time zone, you have incomplete data.
Oracle does not implicitly convert instances of this data type between time zones; this can be done explicitly with the AT TIME ZONE clause. To get the current time as a TIMESTAMP WITH TIME ZONE instance, we can use two functions: SYSTIMESTAMP returns the current time in the database time zone and CURRENT_TIMESTAMP returns it in the current session time zone. The following example uses SYSTIMESTAMP.
SQL> alter session set nls_timestamp_tz_format='YYYY-MM-DD HH24:MI:SS.FF6 TZR';
SQL> select systimestamp as ts_bytes from dual;
SYSTIMESTAMP
----------------------------------
2017-11-23 23:57:04.609608 -08:00
4、本地時區和資料庫時區轉換。TIMESTAMP隱含使用本地時區,預設使用會話時區插入,儲存時預設使用資料庫時區。
TIMESTAMP WITH LOCAL TIME ZONE does not expose the time zone information (to the application, it looks like a TIMESTAMP), but it uses tome zones implicitly: An instance is created without time zone information, the session time zone is assumed. Stored instances are normalized to the database time zone. When the data is retrieved, users see it (again) in the session time zone.
The following example illustrates how TIMESTAMP WITH LOCAL TIME ZONE works: First, a table is created. Then the current time is retrieved and stored into the table ( SYSTIMESTAMP returns TIMESTAMP WITH TIME ZONE, but this is automatically converted to TIMESTAMP WITH LOCAL TIME ZONE ). When the table is then being selected, the returned data changes with the session time zone.
SQL> create table mytimestamps( ts timestamp with local time zone );
SQL> insert into mytimestamps values ( systimestamp );
SQL> alter session set time_zone='Europe/Berlin';
SQL> select * from mytimestamps;
TS
---------------------------------------------------------------------------
2017-11-24 12:55:39.761283
SQL> alter session set time_zone='EST';
SQL> select * from mytimestamps;
TS
---------------------------------------------------------------------------
2017-11-24 06:55:39.761283
Format Masks
Whether we work within an application or a tool like SQL Plus or SQL Developer; whenever we output a DATE or TIMESTAMP instance, we're converting it to VARCHAR2. We can do this explicitly using TO_CHAR or Oracle will do it implcitly. And now NLS format masks kick in - the format mask decides how a DATE is converted to a VARCHAR2 and back. The are defaults for NLS format masks at the database level, we can set them at the session level or we can pass a format mask to the individual TO_CHAR call.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29519108/viewspace-2153769/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle日期型別操作幾個問題Oracle型別
- ORACLE 9I 中的日期格式型別Oracle型別
- Oracle日期型別操作幾個問題(二)Oracle型別
- Oracle基本資料型別儲存格式淺析(三)——日期型別(一)Oracle資料型別
- Oracle基本資料型別儲存格式淺析(三)——日期型別(二)Oracle資料型別
- Oracle基本資料型別儲存格式淺析(三)——日期型別(三)Oracle資料型別
- Oracle基本資料型別儲存格式淺析(三)——日期型別(四)Oracle資料型別
- MongoDB日期型別查詢MongoDB型別
- [置頂] SQL日期型別SQL型別
- 日期型別與String型別的轉換型別
- 【MySQL資料型別2之--日期時間型別】MySql資料型別
- 日期型別轉換問題型別
- elasticsearch之日期型別有點怪Elasticsearch型別
- 在PL/SQL中使用日期型別SQL型別
- Mysql資料庫學習(二):資料型別(數值型別 日期和時間型別 字串型別)MySql資料庫資料型別字串
- 日期型別有問題,如何解決?型別
- 匯入sql時報日期型別錯誤SQL型別
- mysql儲存日期使用什麼型別MySql型別
- 【Hive】日期從整形轉為Date型別Hive型別
- SQL Server日期資料型別DATE的使用SQLServer資料型別
- XSD 日期和時間資料型別資料型別
- 字串與日期型別轉換的工具類字串型別
- Oracle資料型別對應Java型別Oracle資料型別Java
- Oracle Long型別轉換為Clob型別Oracle型別
- 【BBED】使用bbed 修改日期型別的資料型別
- VS2005入門之日期型別型別
- 一對一視訊原始碼,通過日期字串轉換日期型別格式原始碼字串型別
- ORACLE物件型別表Oracle物件型別
- Oracle 儲存型別Oracle型別
- Oracle資料型別Oracle資料型別
- Oracle 資料型別Oracle資料型別
- oracle 10g函式大全–日期型函式Oracle 10g函式
- oracle 10g函式大全--日期型函式Oracle 10g函式
- 新版POI如何獲取日期型別的cell的值型別
- Jackson序列化日期型別的屬性型別
- jquery判空 string型別的日期比較大小jQuery型別
- Struts2日期型別轉換問題???型別
- ORACLE DATE型別和TIMESTAMP型別DUMP換算Oracle型別