Question:
How can I convert for an entire database all CHAR into
VARCHAR2 without losing the data?
Answer:
One option is to use the CREATE TABLE statement with an UNRECOVERABLE
SELECT
from the table you want to modify, using SUBSTR to convert CHAR columns
into
VARCHAR2 columns. e.g.
CREATE TABLE new_foo
UNRECOVERABLE AS
SELECT
SUBSTR( surname,1, 20) SURNAME
FROM foo
DROP TABLE foo
RENAME new_foo TO foo
The SURNAME column should now be a VARCHAR2(20).
Another option is to use something like TOAD to generate a full DDL
script
for the database tables to you want to modify. Now edit the script,
changing
all CHARs to VARCHARs. Export the tables using normal Oracle Export.
Run the
modified script in SQL*Plus to drop and re-create empty table structures
where the columns are now VARCHAR2's. Import the data and set IGNORE=Y
to
ignore the fact that the tables already exist.