How would I make a Varchar2(8) column a date column?

I currently have a column 'COMPDATE' in TBL_APP that is set to VARCHAR2(8) that I would like to alter to make a date column.  The data is arranged as follows CCYYMMDD (20100913).
danmcd0913Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OP_ZaharinCommented:
- first create a new date column. i use a different name:
ALTER TABLE TBL_APP ADD COMPDATES DATE

- then update that new column to be the value of COMPDATE:
UPDATE TBL_APP SET COMPDATES = to_date(COMPDATE,'CCYYMMDD')

- then drop the COMPDATE column and rename the COMPDATES column to COMPDATE.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ajexpertCommented:
This is what I can think of...

1. Add new column in TBL_APP, say TMP_COMPDATE DATE

Alter table TBL_APP add TMP_COMPDATE DATE;

2.  Update new column with the following sql
    UPDATE TBL_APP set TMP_COMPDATE = TO_DATE('COMPDATE, 'YYYYMMDD');

3.  If above goes fine, drop column COMPDATE

4.  Rename TMP_COMPDATE to COMPDATE
0
danmcd0913Author Commented:
Thank you!  The only thing I had to change in the sytax was the CC in the date format it didn't accept 'CCYYMMDD' but did accept 'YYYYMMDD'.  Thanks again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.