如何在Oracle中缩短varchar2字段? [英] How to make a varchar2 field shorter in Oracle?

查看:268
本文介绍了如何在Oracle中缩短varchar2字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个表中有一个字段,它是varchar2,4000字节.有超过50000行.并非所有行在此字段中都有数据.很少有超过255个字节的数据字段,但有一些超过4000个字节.要将表放置在新的应用程序中,我需要将该字段缩短为255个字节.

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.

是否存在一条将长度减少到255的SQL语句?我意识到数据将会丢失,这是新应用程序成本的一部分.剪切应该是任意的,无论何种情况都只是将数据停在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.

推荐答案

update b set text2 = substr(text2,1,255);

然后alter table将列的长度设置为255:

then alter table to set length of column to 255 :

alter table b MODIFY "TEXT2" varchar2(255 byte);

这篇关于如何在Oracle中缩短varchar2字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆