SQL: Changing type of a column while keeping the contents (Oracle)

At work we just needed to change the data type of a column which already contained data. In such a case, a simple alter table statement would not work, because the type can not be changed on non-empty columns. (ORA-01439: column to be modified must be empty to change datatype)

You can achieve this with the following series of statements. In my case, the type of the id column should be changed from int to string. For other datatypes, some more effort might be needed on step two, to get the data into the new column in the right format.

ALTER TABLE TABLE_NAME ADD ID_STR VARCHAR(20);
update TABLE_NAME set ID_STR = ID;

-- FIND OUT ABOUT possible constraints to delete:
-- SELECT * FROM DBA_CONSTRAINTS WHERE table_name = 'TABLE_NAME';
alter table TABLE_NAME drop constraint PK_TABLE_NAME;
alter table TABLE_NAME drop column ID;

alter table TABLE_NAME rename column ID_STR to ID;
-- recreate constraint if needed
alter table TABLE_NAME add CONSTRAINT "PK_TABLE_NAME" PRIMARY KEY (...) ENABLE;