website logo
⌘K
🏠Homepage
👋Introduction
Key Concepts & Architecture
🚀Getting Started
👨‍💻SQL Reference
SQL Queries
SQL Clauses
SQL Data Types
SQL Functions
Schema
🚨Error Handling
🆚Differences Between Oxla vs. PostgreSQL
Docs powered by archbee 

String Type

15min

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:

Create a table
|
CREATE TABLE employee (
employeeName string,
employeeDept string,
employeeRole string
);

INSERT INTO  employee (employeeName, employeeDept, employeeRole)
VALUES 
    ('John','Finance','Staff'),
    ('Maya','Product','Staff'),
    ('Jane','Finance','Staff'),
    ('Phil','HR','Manager');


✍🏻 Use the ' ' mark when you type the string value.

The created table is shown below:

Output
|
+---------------+---------------+---------------+
| employeename  | employeedept  | employeerole  |
+---------------+---------------+---------------+
| John          | Finance       | Staff         |
| Maya          | Product       | Staff         |
| Jane          | Finance       | Staff         |
| Phil          | HR            | Manager       |
+---------------+---------------+---------------+


String with SUBSTR Function

The substr() function extracts a specific number of characters from a string.

Syntax

Syntax
|
substr( string, start_position, length )


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.

Select substr
|
SELECT substr('Watermelon',6,5) AS "Fruit";


The updated table is shown below:

Output
|
+-------------+
| Fruit       |
+-------------+
| melon       |
+-------------+


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.

Syntax
|
LENGTH(string);


Example

Insert value into the string column.

Select length
|
SELECT LENGTH ('UNITED STATES');


The updated table is shown below:

Output
|
+---------+
| length  |
+---------+
| 13      |
+---------+


✅ The length() function will also count spaces.



Updated 11 May 2023
Did this page help you?
Yes
No
PREVIOUS
Interval Type
NEXT
Numeric Type
Docs powered by archbee 
TABLE OF CONTENTS
Overview
Examples
String with SUBSTR Function
Syntax
Example
String with LENGTH Function
Syntax
Example

Dedicated to data analytics that provides 10x faster execution of analytical queries than current state of the art solutions. We are launching SOON! Join the waiting list for more info.




©2022 Oxla