Oracle dbtimezone與os時區不一致的解決辦法

來源:互聯網
上載者:User

Connected to Oracle Database 10g Enterprise Edition Release 10.1.0.2.0   
Connected as sys  
          //查看資料庫時區  
SQL> select dbtimezone from dual;  
DBTIMEZONE  
----------  
+00:00  
          //查看目前時間和時區  
SQL> select systimestamp from dual;  
SYSTIMESTAMP  
--------------------------------------------------------------------------------  
12-4月 -11 02.39.49.421000 下午 +08:00  
          //我明明是在東8區,怎麼資料庫時區顯示為0呢?  
SQL> alter database set time_zone='+8:00';  
ORA-30079: cannot alter database timezone when database has TIMESTAMP WITH LOCAL TIME ZONE columns  
          //從錯誤提示,我們可以看出資料庫中一些表的列的資料類型為:TIMESTAMP WITH LOCAL TIME ZONE  
          //我們得將這些列刪除後,才能更改,下面我們來尋找這些類。  
SQL> select u.name||'.'||o.name||'.'||c.name tsltz_column  
  2  from sys.obj$ o,sys.col$ c,sys.user$ u  
  3  where c.type#=231 and  
  4        o.obj#=c.obj# and  
  5        u.user#=o.owner#;  
TSLTZ_COLUMN  
--------------------------------------------------------------------------------  
OE.ORDERS.ORDER_DATE  
          //我們找到了,是oe使用者下orders表下的列order_date。  
SQL> desc oe.orders;  
Name         Type                              Nullable Default Comments                                                     
------------ --------------------------------- -------- ------- -----------------------------------------------------------  
ORDER_ID     NUMBER(12)                                         PRIMARY KEY column.                                          
ORDER_DATE   TIMESTAMP(6) WITH LOCAL TIME ZONE                  TIMESTAMP WITH LOCAL TIME ZONE column, NOT NULL constraint.  
ORDER_MODE   VARCHAR2(8)                       Y                CHECK constraint.                                            
CUSTOMER_ID  NUMBER(6)                                                                                                       
ORDER_STATUS NUMBER(2)                         Y                0: Not fully entered, 1: Entered, 2: Canceled - bad credit,-  
3: Canceled - by customer, 4: Shipped - whole order, -  
5: Shipped - replacement items, 6: Shipped - backlog on items, -  
7: Shipped - special delivery, 8: Shipped - billed, 9: Shipped - payment plan,-  
10: Shipped - paid   
ORDER_TOTAL  NUMBER(8,2)                       Y                CHECK constraint.  
SALES_REP_ID NUMBER(6)                         Y                References hr.employees.employee_id.  
PROMOTION_ID NUMBER(6)                         Y                Sales promotion ID. Used in SH schema  
          //將其刪除  
SQL> alter table oe.orders drop column order_date;  
Table altered  
          //這樣我們才可以修改時區  
SQL> alter database set time_zone='+8:00';  
Database altered  
          //關閉資料庫  
          //SHUTDOWN is not an SQL command, it is an SQL*Plus command.  
SQL> shutdown immediate;  
Database closed.  
Database dismounted.  
ORACLE instance shut down.  
          //啟動資料庫  
SQL> startup;  
ORACLE instance started.  
Total System Global Area     171966464 bytes  
Fixed Size                     7877988 bytes  
Variable Size                145488364 bytes  
Database Buffers              25165824 bytes  
Redo Buffers                    524288 bytes  
Database mounted.  
Database opened.  
         //查看時區  
SQL> select dbtimezone from dual;  
DBTIMEZONE  
----------  
+08:00 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.