NVARCHAR2 Data Type - Oracle to MariaDB Migration

In Oracle, the NVARCHAR2(n) data type stores variable-length Unicode character strings of up to n characters. The maximum size is 4,000 or 32,767 bytes if the MAX_STRING_SIZE initialization parameter is set to EXTENDED (which is not set by default).

By default, Oracle uses UTF-16 encoding for NVARCHAR2, which requires 2 bytes per character, meaning that the maximum n is 2,000 characters.

In MariaDB, you can use NVARCHAR(n), which can store up to 65,535 characters. However, the effective maximum length is subject to the maximum row size limit of 65,535 bytes (shared among all columns) and the character set used.

Oracle:

  CREATE TABLE specs
  (
    note NVARCHAR2(2000)
  );

MariaDB:

  CREATE TABLE specs
  (
    note NVARCHAR(2000)
  );

Note that NVARCHAR is implemented as VARCHAR with CHARACTER SET UTF in MariaDB:

MariaDB:

  SHOW CREATE TABLE specs;
  /* CREATE TABLE `specs` (
       `note` varchar(2000) CHARACTER SET utf8mb3 COLLATE utf8mb3_uca1400_ai_ci DEFAULT NULL
  ) ... */

Overview

Conversion summary:

Oracle MariaDB
Syntax NVARCHAR2(n) NVARCHAR(n)
Parameter n is the number of characters n is the number of characters
Range 1 ⇐ n ⇐ 4,000 or 32,767 (if MAX_STRING_SIZE=EXTENDED)
bytes
0 ⇐ n ⇐ 65,535
(with 65,535 bytes row limit )
Default n must be specified n must be specified

For more information, see Oracle to MariaDB Migration.