Reputation: 7094
I have column with name DATA_STR
and type DATE
. I need change column type to VARCHAR2(50)
. How can I do it?
Upvotes: 0
Views: 53
Reputation: 59522
It was written already, however I repeat it: Do not do this!
But may you consider to use VIRTUAL COLUMN like this:
ALTER TABLE my_table ADD DATE_CHAR GENERATED ALWAYS AS (TO_CHAR(DATA_STR, 'YYYY-MM-DD HH24:MI:SS') VIRTUAL);
Upvotes: 1
Reputation: 58822
Although it's not recommended, you can follow the steps
Add new (temp) column DATA_STR_VAR
Update it using old column with to_char e.g.:
update tableName set DATA_STR_VAR=to_char(DATA_STR, 'DD-MON-YYYY HH24:MI')
Drop column DATA_STR
Rename DATA_STR_VAR
to DATA_STR
Upvotes: 1