Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Modify the data type of a column with data in Oracle

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report