ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle将表中date数据类型修改为timestamp数据类型

oracle将表中date数据类型修改为timestamp数据类型

原创 Linux操作系统 作者:xcdream6 时间:2012-09-10 12:56:34 0 删除 编辑
   
创建表测试表并插入数据

SQL> create table test(a number(10),b date);
Table created.
SQL> insert into test values(1,sysdate);
1 row created.
SQL> insert into test values(2,sysdate);
1 row created.
SQL> insert into test values(3,sysdate);
1 row created.
SQL> insert into test values(4,sysdate);
1 row created.
SQL> commit;
SQL> select * from test;
         A B
---------- ---------
         1 10-SEP-12
         2 10-SEP-12
         3 10-SEP-12
         4 10-SEP-12
SQL> desc test
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 A                                                  NUMBER(10)
 B                                                  DATE
 
 
修改数据类型
 
SQL> alter table test modify b timestamp;
Table altered.
SQL> select * from test;
         A
----------
B
---------------------------------------------------------------------------
         1
10-SEP-12 11.46.27.000000 AM
         2
10-SEP-12 11.46.41.000000 AM
         3
10-SEP-12 11.47.39.000000 AM

         A
----------
B
---------------------------------------------------------------------------
         4
10-SEP-12 11.47.53.000000 AM
 
 
 
 
 
 
 
SQL> alter table test modify b date;
Table altered.
SQL> select to_char(b,'yyyy-mm-dd hh24:mi:ss') from test
  2  ;
TO_CHAR(B,'YYYY-MM-
-------------------
2012-09-10 11:46:27
2012-09-10 11:46:41
2012-09-10 11:47:39
2012-09-10 11:47:53
SQL> alter table test modify b timestamp;
Table altered.
SQL> select to_char(b,'yyyy-mm-dd hh24:mi:ss') from test;
TO_CHAR(B,'YYYY-MM-
-------------------
2012-09-10 11:46:27
2012-09-10 11:46:41
2012-09-10 11:47:39
2012-09-10 11:47:53
SQL> select * from test;
         A
----------
B
---------------------------------------------------------------------------
         1
10-SEP-12 11.46.27.000000 AM
         2
10-SEP-12 11.46.41.000000 AM
         3
10-SEP-12 11.47.39.000000 AM

         A
----------
B
---------------------------------------------------------------------------
         4
10-SEP-12 11.47.53.000000 AM

SQL>

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27146953/viewspace-743022/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-07-10

  • 博文量
    8
  • 访问量
    22610