is modifying all database columns varchar2 size to be 4000 char, will affect the database or the storage?

40 Views Asked by At

oracle database 19.20 c the size of the column will be reserved for 4000 char immediately or it will reserve as much they need?

i tried to change all varchar2 columns of some table to be 4000 to avoid modifying the size later.

1

There are 1 best solutions below

0
Littlefoot On

From my point of view, absolutely wrong approach. Why would all strings be stored into (var)char(4000)? (with char being even worse, as you'd reserve 4000 characters, fixed, with all values right-padded with spaces up to whole column length.)

First name - 4000 characters? Do you know anyone who has that long first name? Phone number? Sex?

Shortly: plan data model; think about data you're about to store; wisely choose datatypes (and their length).

As of program units you'll write: variables, that refer to columns, should inherit their datatype. For example:

No :  v_first_name varchar2(10);
Yes:  v_first_name employees.first_name%type

because if it turns out that you didn't guess it right initially, you'd just modify column length, but all procedures would just work, without you having to modify a single bit of code.