Home
NCHAR and NVARCHAR2 size in bytes
Description
-
The NCHAR and NVARCHAR2 size in bytes rule states that the size of NCHAR and NVARCHAR2 data types must be specified in bytes rather than characters. The maximum size of an NCHAR or NVARCHAR2 column is 2000 bytes. The number of characters that can be stored in an NCHAR or NVARCHAR2 column is dependent on the number of bytes specified for the column. For example, if the size of the column is specified as 10 bytes, then the maximum number of characters that can be stored in the column is 10 characters.
Key Benefits
- NCHAR and NVARCHAR2 size in bytes: Allows storage of up to 4000 bytes of character data, compared to the 2000 bytes of character data that VARCHAR2 can store.
- Unicode Support: NCHAR and NVARCHAR2 support Unicode characters, allowing for the storage of characters from multiple languages.
- Efficient Memory Usage: NCHAR and NVARCHAR2 data types use less memory than VARCHAR2 data types.
Non-compliant Code Example
DECLARE firstname NVARCHAR2(75 BYTE); --Non compliant code (NCHAR and NVARCHAR2 size specified in bytes) lastname NVARCHAR2(75 BYTE); --Non compliant code (NCHAR and NVARCHAR2 size specified in bytes) landmark NCHAR(75 BYTE); --Non compliant code (NCHAR and NVARCHAR2 size specified in bytes) BEGIN SELECT FIRSTNAME, LASTNAME, LANDMARK INTO firstname,lastname,landmark FROM CUSTOMERS; END;
Compliant Code Example
DECLARE firstname NVARCHAR2(75); --Compliant code lastname NVARCHAR2(75); --Compliant code landmark NCHAR(75); --Compliant code BEGIN SELECT FIRSTNAME, LASTNAME, LANDMARK INTO firstname,lastname,landmark FROM CUSTOMERS; END;