Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

convert number column to date column

981609Dec 25 2012 — edited Dec 26 2012
I have a partitioned table with ~50 million rows that was setup with a number(10) instead
of a date column. All the data in the table is ALWATS in this format YYYYMMDD
Code: [Select all] [Show/ hide]CREATE TABLE T1.monthly
(
SEQ_NUM NUMBER(10) NOT NULL,
DAY_DK NUMBER(10) NOT NULL
)
TABLESPACE USERS
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
LOGGING
PARTITION BY RANGE (DAY_DK)
(
PARTITION DEC_2012 VALUES LESS THAN (20130101)
LOGGING
NOCOMPRESS
TABLESPACE USERS
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 8M
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
),
PARTITION POST_2017 VALUES LESS THAN (20510101)
NOLOGGING
NOCOMPRESS
TABLESPACE USERS
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
BUFFER_POOL DEFAULT
)
)
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;

some sample data

SEQ_NUM DAY_DK
---------- ----------
990 20121225
991 20121225
992 20121225
993 20121225
994 20121225
995 20121225
996 20121225
997 20121225
998 20121225
999 20121225

When I use the exchange partition method the parition is able to move the data from "monthly" table to "mth" table.
Code: [Select all] [Show/ hide]desc t1.mth; ### my temorary table
Name Null? Type
----------------------------------------- -------- ----------------------------
SEQ_NUM NUMBER(10)
DAY_DK NUMBER(10)

Than when I try to alter my temp table "mth". I get an error table must be empty to change
column types.
Code: [Select all] [Show/ hide]alter table n546830.mth modify (DAY_DK date);

Next I tried making my temporary table "mth" a date column. When I an the exchange partiton
command I get the following error:
Code: [Select all] [Show/ hide]alter table t1.monthly exchange partition DEC_2012
with table t1.mth without validation;
alter table n546830.monthly exchange partition DEC_2012 with table n546830.mth without validation
*
ERROR at line 1:
ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION

I am thinking maybe instead of the parition exchange I can use pl sql to move most of the row over to a new table (all except the number(10) coluimn, than use some procedure or function to convert the number to a date? not being a developer I was wondering if somebody can verify this is a good idea ( keep in mind I want to generate the min amount of undo as possible). In addtion, can somebody provide me a template. In particular on how to convert the number to date column row by row.

Thanks to all who answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 23 2013
Added on Dec 25 2012
2 comments
86 views