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

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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值