sql - Reduce varchar2(n char) size to varchar2(n) when value length = n but lentgthb = x*n -


i have table:

create table test_val (   name varchar2(10 char) not null );  

let's insert following:

insert test_val (name) values('££££££££££'); --data here may variable characters string size may vary 10 40 bytes 

now value in table 10 characters 20 bytes.

and want reduce size of column 10 bytes, don't care data loss. following:

update test_val set name = substr(name,1,10) lengthb(name)>10;  alter table test_val modify name varchar2(10); 

and error value in column big, because substr(name,1,10) leaves 10 symbols.

so question is: there substr alternative substringing values number of bytes, if not, there way reduce column value run alter table?

thanks

there substrb function calculates in bytes (as substrc, substr2, , substr4 number of unicode characters, ucs2, , ucs4 code points). if database character set al32utf8, remember characters may require between 1 , 4 bytes of storage-- don't know off top of head happens if try 10 bytes of data string when cut off character in middle.


Comments