| Converting number column to date column [message #573254] |
Tue, 25 December 2012 11:33  |
 |
BeefStu
Messages: 184 Registered: October 2011
|
Senior Member |
|
|
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
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.
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.
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:
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
Does anybody know of an method I can use to convert a number(10) to date column and keep the informaiton in a table. Note, I dont care about HH:MM:SS as I never had that inforation to
begin with and would be happy to set that part of the date column to all zeroes "00:00:00"
Any examples would or advice on how to proceed would be appreciated. Thanks to all who answer
[EDITED by LF: fixed [code] tags]
[Updated on: Tue, 25 December 2012 12:16] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Converting number column to date column [message #573502 is a reply to message #573486] |
Sat, 29 December 2012 13:50  |
cookiemonster
Messages: 9165 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
BlackSwan wrote on Sat, 29 December 2012 16:02
In the SELECT statement above first you convert "DAY_DK" from Date to String using TO_CHAR();
then you convert that results back to DATE using TO_DATE().
WHY?
I suggest you re-read the topic from the beginning. day_dk is not a date.
EDIT: fixed tags
[Updated on: Sat, 29 December 2012 13:51] Report message to a moderator
|
|
|
|