// data type reference

VARCHAR and NVARCHAR

The everyday string type, plus the length and encoding traps each engine adds.

Family
텍스트
Missing in
None of the five
Gotchas
5 listed

Engine by engine

All five engines have a VARCHAR, but the limit is bytes or characters, MAX or 4000, enforced or ignored - and Oracle's empty string is NULL.

VARCHAR / NVARCHAR in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
엔진 타입 저장소 메모
SQL Server VARCHAR(n) / VARCHAR(MAX) / NVARCHAR n bytes + 2, or 2 GB (MAX) VARCHAR(n) allows n up to 8,000 bytes, NVARCHAR(n) up to 4,000 UTF-16 code units (emoji take two); the collation decides casing and sorting.
PostgreSQL VARCHAR(n) / VARCHAR bytes used + 1 (or 4) bytes Length in characters; VARCHAR without (n) behaves like TEXT, up to 1 GB.
MySQL VARCHAR(n) bytes used + 1 or 2 bytes n counts characters; utf8mb4 caps it at 16,383, and all columns together must fit the 65,535-byte row limit.
SQLite VARCHAR(n) (TEXT affinity) variable TEXT affinity: no length enforcement, no padding, no separate Unicode type.
Oracle VARCHAR2(n BYTE|CHAR) up to 4000 bytes VARCHAR exists as ANSI syntax, but VARCHAR2 is the idiomatic (and empty-string-is-NULL) type; 32,767 bytes with extended data types.

Gotchas

Where the engines disagree. These tend to surface as bugs during a migration or a port.

  1. Oracle VARCHAR2 sizes in bytes unless told otherwise: in AL32UTF8, VARCHAR2(50) rejects a 17-character Chinese or Japanese name (3 bytes per character, 51 bytes). Declare VARCHAR2(n CHAR).
  2. SQL Server's VARCHAR is a legacy code page while NVARCHAR is UTF-16: emoji or multilingual data in VARCHAR can become ? unless the column uses a UTF-8 collation.
  3. Oracle treats the empty string '' as NULL: inserting '' into VARCHAR2 stores NULL and IS NULL matches it. None of the other engines do this.
  4. MySQL enforces the 65,535-byte row limit across all columns together, and a utf8mb4 VARCHAR tops out at 16,383 characters: VARCHAR(20000) fails CREATE TABLE with error 1074.
  5. SQLite's VARCHAR(n) does not enforce n at all; validation moves entirely to the application.

Common questions

VARCHAR(n) or VARCHAR(MAX)?

n when a real limit exists: it documents intent, validates input and helps the optimizer. MAX is for genuinely unbounded text.

VARCHAR or NVARCHAR in SQL Server?

NVARCHAR for user-entered multilingual text. VARCHAR with a UTF-8 collation is an option from SQL Server 2019 onward.

Why VARCHAR2 in Oracle?

History: Oracle reserved VARCHAR for future ANSI semantics and guaranteed VARCHAR2 would never change, so everyone uses VARCHAR2.

// map types before you move data

Map a type to the other four engines

The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.