Get the App
SLTechnology News&Howtos  ›  Database  › 

Modify the data type of a column with data in Oracle

Shulou Source: shulou.com Published: 2022-06-01 09:47:33 10月03日 Update

Because yesterday I went to another company to maintain the data, and after importing the data, I found that the column of element contents in the table was empty. At first, I thought there was a problem with the data, but later I found that the type of the data in the table was of CLOB type. If the data in EXCLE did not match directly, I asked the leader. The leader said that the CLOB type was changed to varchar2 type, not to mention the previous step:

Because there is already data in this column, you need to do the following:

* modify the original field name * /

ALTER TABLE table name RENAME COLUMN field name TO field name 1

/ * add a field with the same name as the original field * /

ALTER TABLE table name ADD field name VARCHAR2 (30)

/ *

Update the original data to the new field

It is important to note that it must be shown for data type conversion (unlike MSSQL)

, /

UPDATE table name SET field name = CAST (field name 1 AS VARCHAR2 (30))

/ * Delete the original backup field * /

ALTER TABLE table name DROP COLUMN field name 1

Tags: Fields data type company content backup steps elements this is question update belt Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Shulou Information Microsoft Xiaomi