Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL difference between varchar2(n) and varchar2(n char)

Tags:

sql

oracle

Scripts here at work always declare varchar2 columns as varchar2(n char). I do not see any difference and just curious. Thanks!

like image 978
Ram Avatar asked Jan 14 '23 10:01

Ram


1 Answers

Based on this resource

Oracle9i and above allow Varchar2 columns to be defined as a number of bytes VARCHAR2(50 BYTE) or a number of characters VARCHAR2(50 CHAR), the latter is useful if the database is ever converted to run a double-byte character set (such as Japanese), you won't have to edit the column sizes. The default measure, normally BYTE, is set with nls_length_semantics.

If you create a column as Varchar2 (50) but only store 10 bytes, then Oracle will only save 10 bytes to disc. This does not mean that you should just create Varchar2 (4000) columns 'just in case the space is needed', that is a really bad idea which will reduce the performance and maintainability of your application.

like image 77
Wayan Wiprayoga Avatar answered Jan 16 '23 18:01

Wayan Wiprayoga