Difference between VARCHAR2(10 CHAR) and NVARCHAR2(10)

前端 未结 4 1693
有刺的猬
有刺的猬 2020-11-29 21:59

I\'ve installed Oracle Database 10g Express Edition (Universal) with the default settings:

SELECT * FROM NLS_DATABASE_PARAMETERS;


        
4条回答
  •  再見小時候
    2020-11-29 22:44

    • The NVARCHAR2 stores variable-length character data. When you create a table with the NVARCHAR2 column, the maximum size is always in character length semantics, which is also the default and only length semantics for the NVARCHAR2 data type.

      The NVARCHAR2data type uses AL16UTF16character set which encodes Unicode data in the UTF-16 encoding. The AL16UTF16 use 2 bytes to store a character. In addition, the maximum byte length of an NVARCHAR2 depends on the configured national character set.

    • VARCHAR2 The maximum size of VARCHAR2 can be in either bytes or characters. Its column only can store characters in the default character set while the NVARCHAR2 can store virtually any characters. A single character may require up to 4 bytes.

    By defining the field as:

    • VARCHAR2(10 CHAR) you tell Oracle it can use enough space to store 10 characters, no matter how many bytes it takes to store each one. A single character may require up to 4 bytes.
    • NVARCHAR2(10) you tell Oracle it can store 10 characters with 2 bytes per character

    In Summary:

    • VARCHAR2(10 CHAR) can store maximum of 10 characters and maximum of 40 bytes (depends on the configured national character set).

    • NVARCHAR2(10) can store maximum of 10 characters and maximum of 20 bytes (depends on the configured national character set).

    Note: Character set can be UTF-8, UTF-16,....

    Please have a look at this tutorial for more detail.

    Have a good day!

提交回复
热议问题