4

此处的脚本始终将 varchar2 列声明为 varchar2(n char)。我看不出有什么区别,只是好奇。谢谢!

4

2 回答 2

6

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.

于 2013-05-10T02:44:00.013 回答
3

The syntax is VARCHAR2(n) and VARCHAR2(n BYTE|CHAR)

The default for (n) and (n BYTE) are usually the same. (n CHAR) may not be equivalent to (n|BYTE) or (n) unless you set NLS_LENGTH_SEMANTICS parameter to what you want, CHAR or BYTE. This setting is for character sets that use multibyte characters. Generally not for UTF8, for example.

DO NOT change it, since there is existing code that works.

I would guess that (n) == (n CHAR) == (n BYTE) or your system.

于 2013-05-10T02:42:30.217 回答