Skip to main content

VARCHAR Type

VARCHAR (Variable Character) is a data type used in databases to store character strings. When storing multibyte UTF-8 characters, each character may require between 1 to 4 bytes, affecting the actual storage limit. If a value exceeds the allowed length, it might be truncated, with truncation potentially occurring based on UTF-8 character boundaries.

Syntax

VARCHAR

VARCHAR Length

VARCHAR can have defined maximum lengths of 1 to 65000.

Literals

String literals for VARCHAR are enclosed in single quotes ().

'Hello World'
'12345'
'Special characters: @#$%^&*' 

Examples

-- Example 1: Literals
> SELECT 'Hello World';
'Hello World'
              
> SELECT '12345';
'12345'

> SELECT '@#$%^*';
'@#$%^*'

-- Example 2: Casting to VARCHAR
> SELECT CAST(12345 AS VARCHAR);
'12345'