如何在 Oracle 中缩短 varchar2 字段?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8404194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a varchar2 field shorter in Oracle?
提问by user761758
I have a field in a table that is varchar2, 4000 bytes. There are over 50000 rows. Not all rows have data in this field. Few data fields are over 255 bytes, but some are 4000. To place the table in a new application, I need to shorten the field to 255 bytes.
我在表中有一个字段是 varchar2,4000 字节。有超过 50000 行。并非所有行在该字段中都有数据。很少有数据字段超过 255 字节,但有些是 4000。要将表放入新应用程序中,我需要将字段缩短为 255 字节。
Is there a SQL statement that will reduce the length to 255? I realize data will be lost, that is part of the cost of the new application. The cut should be arbitrary, just stopping the data at 255 no matter the circumstance.
是否有将长度减少到 255 的 SQL 语句?我意识到数据会丢失,这是新应用程序成本的一部分。切割应该是任意的,无论情况如何,只要在 255 处停止数据即可。
回答by xQbert
update b set text2 = substr(text2,1,255);
then alter table
to set length of column to 255
:
然后alter table
将列的长度设置为255
:
alter table b MODIFY "TEXT2" varchar2(255 byte);