創建並填充新列...
SQL> alter table t23
2 add new_col timestamp(3) with time zone
3/
Table altered.
SQL> update t23
2 set new_col = col3
3/
7 rows updated.
SQL> select to_char(new_col,'DD-MON-YYYY HH24:MI:SS.FF3 TZR') new_col
2 from t23
3/
NEW_COL
----------------------------
22-MAR-2010 03:20:58.000 PST
21-MAR-2010 03:20:58.000 PST
20-MAR-2010 03:20:58.000 PST
19-MAR-2010 03:20:58.000 PST
18-MAR-2010 03:20:58.000 PST
17-MAR-2010 03:20:58.000 PST
16-MAR-2010 03:20:58.000 PST
7 rows selected.
SQL>
所以現在COL3的值設置到了中午UTC或GMT,我們英國人(和Oracle)知道:
SQL> alter session set time_zone = 'GMT'
2/
Session altered.
SQL> update t23
2 set col3 =
3 cast(to_char(col3, 'DD-MON-YYYY')||'12:00:00' as timestamp) at time zone sessiontimezone
4/
7 rows updated.
SQL>
讓我們來看看結果:
SQL> alter session set time_zone = 'PST'
2/
Session altered.
SQL> select to_char(new_col,'DD-MON-YYYY HH24:MI:SS.FF3 TZR') as orig_val
2 , to_char(col3,'DD-MON-YYYY HH24:MI:SS.FF3 TZR') as upd_val
3 from t23
4/
ORIG_VAL UPD_VAL
---------------------------- ----------------------------
22-MAR-2010 03:20:58.000 PST 22-MAR-2010 12:00:00.000 GMT
21-MAR-2010 03:20:58.000 PST 21-MAR-2010 12:00:00.000 GMT
20-MAR-2010 03:20:58.000 PST 20-MAR-2010 12:00:00.000 GMT
19-MAR-2010 03:20:58.000 PST 19-MAR-2010 12:00:00.000 GMT
18-MAR-2010 03:20:58.000 PST 18-MAR-2010 12:00:00.000 GMT
17-MAR-2010 03:20:58.000 PST 17-MAR-2010 12:00:00.000 GMT
16-MAR-2010 03:20:58.000 PST 16-MAR-2010 12:00:00.000 GMT
7 rows selected.
SQL>
剩下要做的就是丟棄備份列...
SQL> alter table t23 drop column new_col
2/
Table altered.
SQL>
儘管如果它是一個大桌子,您可能更喜歡將其設置爲UNUSED,然後在較慢的時間內放下它。
來源
2010-03-23 12:13:01
APC