您的位置:首页 > 其它

ocp-047-30 timestamp with local time zone 和timesatamp with time zone

2014-06-24 23:46 351 查看
30. You need to create a table for a banking application with the following

considerations:

1) You want a column in the table to store the duration of the credit period.

2) The data in the column should be stored in a format such that it can be

easily added and subtracted with

3) date type data without using the conversion functions.

4) The maximum period of the credit provision in the application is 30 days.

5) The interest has to be calculated for the number of days an individual

has taken a credit for.

Which data type would you use for such a column in the table?

A. INTERVAL YEAR TO MONTH

B. INTERVAL DAY TO SECOND

C. TIMESTAMP WITH TIME ZONE

D. TIMESTAMP WITH LOCAL TIME ZONE

Answer:B

timestamp with local time zone 和timesatamp with time
zone的最大区别就是,前者在用户提交时间给数据库的时,该类型会转换成数据库的时区来保存数据,即数据库保存的时间是数据库本地时区,当别的用户访问数据库时oracle会自动将该时间转换成当前客户端的时间。

例子:

1、创建表
SQL> CREATE TABLE TIMESTAMP_TEST(

2 TIME DATE,

3 TIMESTP TIMESTAMP(3),

4 TIMESTP_TZ TIMESTAMP(3) WITH TIME ZONE,

5 TIMESTP_LTZ TIMESTAMP(3) WITH LOCAL TIME ZONE);

2、添加数据

SQL> INSERT INTO TIMESTAMP_TEST VALUES(SYSDATE,SYSDATE,SYSDATE,SYSDATE);

SQL> select dbtimezone ,sessiontimezone from dual;

3、查询dbtimezone和sessiontimezone的值

DBTIMEZONE

------------

SESSIONTIMEZONE

--------------------------------------------------------------------------------

+00:00

-04:00

4、查看数据的值

SQL> SELECT * FROM TIMESTAMP_TEST;

TIME

------------

TIMESTP

---------------------------------------------------------------------------

TIMESTP_TZ

---------------------------------------------------------------------------

TIMESTP_LTZ

---------------------------------------------------------------------------

24-JUN-14

24-JUN-14 11.26.20.000 AM

24-JUN-14 11.26.20.000 AM -04:00

24-JUN-14 11.26.20.000 AM

5、修改会话的time_zone值

alter session set time_zone='+10:00';

6、查看结果

SQL> SELECT * FROM TIMESTAMP_TEST;

TIME

------------

TIMESTP

---------------------------------------------------------------------------

TIMESTP_TZ

---------------------------------------------------------------------------

TIMESTP_LTZ

---------------------------------------------------------------------------

24-JUN-14

24-JUN-14 11.26.20.000 AM

24-JUN-14 11.26.20.000 AM -04:00

25-JUN-14 01.26.20.000 AM // 在原来的基础上往前推进14小时

参考文件:http://blog.sina.com.cn/s/blog_48e13c9e0100wydj.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: