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.

Position Function In Sql in SQL

Position Function In Sql in SQL

POSITION Function in SQL

The POSITION function returns the starting position of a substring within a string. It returns the 1-based index of the first occurrence of the substring. If the substring is not found, it returns 0.


Syntax:

POSITION(substring IN string)
  • substring — the substring you want to find.

  • string — the string to search in.


Example:

Find the position of 'cat' in a string:

SELECT POSITION('cat' IN 'The black cat sat on the mat') AS position;

Result:

position
11

Notes:

  • POSITION is part of the SQL standard and supported by PostgreSQL, MySQL (since 8.0), Oracle (via INSTR), and others.

  • Similar to CHARINDEX in SQL Server.

  • Positions are 1-based (first character is position 1).


If you want, I can provide examples for specific databases or related functions!

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