How to Use SUBSTR in Oracle

Last updated August 25, 2026 · By the SaturnSQL team

SUBSTR(string, position, length) extracts a substring using 1-based positions. A negative position counts backward from the end of the string.

SELECT SUBSTR('Order-2024-0091', 1, 5) AS prefix
FROM dual;

Positions start at 1, not 0

The first character of the string is position 1. SUBSTR(order_code, 7, 4) starts reading at the 7th character and takes the next 4.

SELECT order_code, SUBSTR(order_code, 7, 4) AS year_part
FROM orders;

A negative start position counts backward from the end, which is handy for suffixes: SUBSTR(order_code, -4) returns the last 4 characters regardless of the string's length. Omitting the length argument returns everything from the start position through the end of the string, so SUBSTR(email, INSTR(email, '@') + 1) grabs the whole domain after the @ sign.

Run this in SaturnSQL

SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.

Try it free

Do more with Oracle

Related Oracle guides