Oracle Change Datatype

** Credit Web
# Step 1 Add New colume new datatype
ALTER TABLE table
ADD (column datatype [DEFAULT expr]
[, column datatype]…);
# Step 2 Copy old data colume to new data colume

UPDATE table1 alias1
SET column = (SELECT expression
FROM table1 alias2
WHERE alias1.column =
alias2.column);
### WHERE alias1.column=alias2.column); will be unique key
# Step 3 Drop old data colume

ALTER TABLE table
DROP column CASCADE CONSTRAINS;
# [optional] Step 4 if u not accept new name will be repeat create old name but new datatype colume
ALTER TABLE table
ADD (column datatype [DEFAULT expr]
[, column datatype]…);
# [optional] Step 5 if u not accept new name will be repeat create old name but new datatype colume and repeat copy data
UPDATE table1 alias1
SET column = (SELECT expression
FROM table1 alias2
WHERE alias1.column =
alias2.column);
# [optional] Step 6 if u not accept new name will be repeat create old name but new datatype colume and repeat copy data and add constraint
ALTER TABLE table
ADD [CONSTRAINT constraint] type (column);

0 comments:

Loading