String Type
This page provides a clear explanation of the most commonly used data type, the String type. We will give some examples, including the one using the string function, which allows you to store and manage the string data.
Overview
The string data type is a UTF8 encoded string with Unicode support, which stores a sequence of characters (text).
Examples
Let’s create an employee table with a string data type in each column:
✍🏻 Use the ' ' mark when you type the string value.
The created table is shown below:
String with SUBSTR Function
The substr() function extracts a specific number of characters from a string.
Syntax
Let’s analyze the above syntax:
- string is the specified string.
- start_position is used as the starting position, specifying the part from where the substring is to be returned. It is written in an integer value.
- length is used to determine the number of characters to be extracted. It can be one or more characters.
ℹ️ The first position in the string is 1.
Example
Insert value into the string column.
The updated table is shown below:
String with LENGTH Function
The length() function returns a number of characters in a string.
💡 The number of characters might be different from the byte length.
Syntax
The length function will take a string as a parameter.
Example
Insert value into the string column.
The updated table is shown below:
✅ The length() function will also count spaces.
