Changing the data type of a column in Oracle

user1232622 picture user1232622 · Apr 25, 2012 · Viewed 65.7k times · Source

I created the following table

CREATE TABLE PLACE(
  POSTCODE VARCHAR(10) PRIMARY KEY,
  STREET_NAME VARCHAR(10),
  COUNTY VARCHAR(10),
  CITY VARCHAR(10));  

I want to change the name, county and city from varchar(10) to varchar(20). How do I do that?

Answer

Justin Cave picture Justin Cave · Apr 25, 2012
ALTER TABLE place
  MODIFY( street_name VARCHAR2(20),
          county      VARCHAR2(20),
          city        VARCHAR2(20) )

Note that I am also changing the data type from VARCHAR to VARCHAR2 to be more conventional. There is no functional difference at present between the two though the behavior of VARCHAR may change in the future to match the SQL standard.