INTERVAL YEAR TO MONTH数据类型是用来存储两个时间戳之间的时间差,这个差值精确到时间的年和月。
oracle文档里这样描述:
Stores a period of time in years and months, where year_precision is the number of digits in the YEAR datetime field. Accepted values are 0 to 9. The default is 2. The size is fixed at 5 bytes.
Oracle语法:
INTERVAL 'integer [- integer]' {YEAR | MONTH} [(precision)][TO {YEAR | MONTH}]
示例:(参考)
|
SQL> CREATE TABLE coupons ( 2 coupon_id INTEGER, 3 name VARCHAR2(30), 4 duration INTERVAL YEAR(3) TO MONTH 5 );
Table created.
SQL> SQL> SQL> INSERT INTO coupons (coupon_id, name, duration) VALUES (1, '$1 off Z Files', INTERVAL '1' YEAR);
1 row created.
SQL> INSERT INTO coupons (coupon_id, name, duration) VALUES (2, '$2 off Pop 3', INTERVAL '11' MONTH);
1 row created.
SQL> INSERT INTO coupons (coupon_id, name, duration) VALUES (3, '$3 off Modern Science', INTERVAL '14' MONTH);
1 row created.
SQL> INSERT INTO coupons (coupon_id, name, duration) VALUES (4, '$2 off Tank War', INTERVAL '1-3' YEAR TO MONTH);
1 row created.
SQL> INSERT INTO coupons (coupon_id, name, duration) VALUES (5, '$1 off Chemistry', INTERVAL '0-5' YEAR TO MONTH);
1 row created.
SQL> INSERT INTO coupons (coupon_id, name, duration) VALUES (6, '$2 off Creative Yell', INTERVAL '123' YEAR(3));
1 row created.
SQL> SQL> SELECT * FROM coupons;
COUPON_ID NAME DURATION ---------- ------------------------------ --------------------------------------------------------------------------- 1 $1 off Z Files +001-00 2 $2 off Pop 3 +000-11 3 $3 off Modern Science +001-02 4 $2 off Tank War +001-03 5 $1 off Chemistry +000-05 6 $2 off Creative Yell +123-00
6 rows selected.
SQL> SQL> SQL> SQL> drop table coupons; |
参考:
1、INTERVAL YEAR TO MONTH数据类型 http://www.itpub.net/thread-1023060-1-1.html
2、Data Types http://docs.oracle.com/cd/E11882_01/server.112/e17118/sql_elements001.htm
Table 3-1 Built-in Data Type Summary
3、使用INTERVAL YEAR TO MONTH类型 http://mba.shengwushibie.com/itbook/BookChapter.asp?id=34435
4、INTERVAL数据类型 http://baggio785.itpub.net/post/31233/286119