Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Substring Function In Sql in SQL

Substring Function In Sql in SQL

The SUBSTRING function in SQL is used to extract a portion of a string, starting at a specified position, optionally for a given length.


? Syntax

SUBSTRING(string, start_position, length)
  • string: The source string.

  • start_position: The starting position (1-based index).

  • length: Number of characters to extract.


? Behavior

  • Extracts a substring beginning at start_position.

  • Extracts length characters from the starting point.

  • If length exceeds the string’s remaining length, returns up to the end.

  • If start_position is beyond the string length, returns an empty string.

  • Some dialects allow start_position to be negative to count from the end.


? Examples

SELECT SUBSTRING('OpenAI ChatGPT', 1, 6) AS Extracted;  -- 'OpenAI'SELECT SUBSTRING('OpenAI ChatGPT', 8, 7) AS Extracted;  -- 'ChatGPT'SELECT SUBSTRING('OpenAI ChatGPT', 8) AS Extracted;     -- 'ChatGPT' (if length omitted in some DBs)

Dialect Notes

DatabaseFunction NameNotes
SQL ServerSUBSTRINGRequires all three parameters
MySQLSUBSTRING or SUBSTRlength is optional
PostgreSQLSUBSTRINGSupports various syntaxes
OracleSUBSTRSimilar behavior

If you want, I can show you how to use SUBSTRING in your specific SQL database!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql