invantive documentationpart of invantive cloud
Invantive Support ForumsLog In / Sign Up

CHARINDEX

Syntax

%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    Start((START)) --> CHARINDEX[CHARINDEX]:::quoted
    CHARINDEX --> End((END))

Purpose

The CHARINDEX SQL function retrieves the position with the first occurrence of a search text in another text. Search starts at the first position or, when specified, at the indicated start location.

Parameters:

  • Search text (varchar2): text to search for.
  • Full text (varchar2): text to be searched.
  • Start Position (optional, int32): start position of search. Defaults to 0.

Returns: the position of the search text inside the full text as int32.

Examples

The following example retrieves the position of c in abcdefg:

select charindex('c', 'abcdefg')

--------
3

The following example retrieves the position of c in abcdefgabcdefg starting search at position 5:

select charindex('c', 'abcdefgabcdefg', 5)

--------
10