Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10

SUBSTRING

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The SUBSTRING() function calculates the substring of a string given a starting position and optionally, a length. See also LEFT, RIGHT.

SELECT
  substring('hello world', 7),
  substring('hello world', 7, 1);
create.select(
  substring("hello world", 7),
  substring("hello world", 7, 1)).fetch();

The result being

+-----------+-----------+
| substring | substring |
+-----------+-----------+
| world     | w         |
+-----------+-----------+

Dialect support

This example using jOOQ:

substring(val("hello world"), 7)

Translates to the following dialect specific expressions:

Access

mid('hello world', 7)

ASE, SQLDataWarehouse, SQLServer

substring('hello world', 7, 2147483647)

Aurora MySQL, Aurora Postgres, BigQuery, ClickHouse, CockroachDB, DuckDB, Exasol, H2, HSQLDB, Hana, MariaDB, MemSQL, MySQL, Postgres, Redshift, Snowflake, Sybase, Trino, Vertica, YugabyteDB

substring('hello world', 7)

DB2, Derby, Informix, Oracle, SQLite

substr('hello world', 7)

Firebird, Teradata

substring('hello world' FROM 7)
Generated with jOOQ 3.20. Translate your own SQL on our website

References to this page

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo