Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a varchar2 field shorter in Oracle?

Tags:

oracle

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.

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.

like image 494
user761758 Avatar asked Dec 06 '11 17:12

user761758


1 Answers

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

then alter table to set length of column to 255 :

alter table b MODIFY "TEXT2" varchar2(255 byte);
like image 189
xQbert Avatar answered Oct 13 '22 23:10

xQbert