5

残念ながら、TIMESTAMP(6)の代わりに誤って定義された列のペアがありますTIMESTAMP(6) WITH TIME ZONE。これらの列を古い間違ったデータ型から新しい正しいデータ型に移行したいと思います。その上、値はE(S | D)Tでキャプチャされているように見え、UTCでの値が必要です。

これまでのところ、私が持っている最高のものは次のとおりです。

alter table OOPSIE_TABLE add (
    NEW_COLUMN_A timestamp(6) with time zone,
    NEW_COLUMN_B timestamp(6) with time zone
);
update OOPSIE_TABLE set
    NEW_COLUMN_A = COLUMN_A,
    NEW_COLUMN_B = COLUMN_B
;
alter table OOPSIE_TABLE drop column (
    COLUMN_A,
    COLUMN_B
);
alter table OOPSIE_TABLE rename column NEW_COLUMN_A to COLUMN_A;
alter table OOPSIE_TABLE rename column NEW_COLUMN_B to COLUMN_B;

15-JUN-12 05.46.29.600102000 PM -04:00残念ながら、それは私が望むときに、のように見えるデータを私に残します15-JUN-12 09.46.29.600102000 PM UTC(またはOracleがそれをフォーマットします)。

やったのですが、select dbtimezone from dual;表示されて+00:00いるので、どうすればいいのかわかりません。理想的には、これを純粋なDMLで実行し、古い日付値(America / New_Yorkタイムゾーンにあると確信しています)に基づいてDSTを考慮に入れることができます。

4

2 に答える 2

6

@JustinCaveの少しの助けを借りて、私は次の解決策にたどり着きました。これは私が望んでいたことを正確に達成します。

-- Rename the old columns so we can use them as a data source *AND* so
-- we can roll back to them if necessary.
alter table OOPSIE_TABLE rename column COLUMN_A to OLD_COLUMN_A;
alter table OOPSIE_TABLE rename column COLUMN_B to OLD_COLUMN_B;
-- Define COLUMN_A and COLUMN_B to have TIME ZONE support.
alter table OOPSIE_TABLE add (
    COLUMN_A timestamp(6) with time zone,
    COLUMN_B timestamp(6) with time zone
);
-- Populate the "new" columns with the adjusted version of the old data.
update OOPSIE_TABLE set
    COLUMN_A = from_tz(OLD_COLUMN_A, 'America/New_York') at time zone 'UTC',
    COLUMN_B = from_tz(OLD_COLUMN_B, 'America/New_York') at time zone 'UTC'
;
于 2012-06-19T18:50:12.610 に答える
2

私にとってはよさそうだ。

`SELECT SYS_EXTRACT_UTC(TIMESTAMP '2012-06-15 05:46:20 -04:00') FROM DUAL;`

与える:

2012-06-15 09:46:20

UTCと4時間の差がある国に住んでいるだけです。

また、次のようなものを試してください。

SELECT to_char(new_column_a, 'YYYY-MM-DD HH24:MI:SS TZD'), sys_extract_utc(new_column_a) FROM oopsie_table;
于 2012-06-19T07:12:04.803 に答える