Share via:


Dear Readers,

In this article, we will learn about INSTR FUNCTION IN TERADATA


Searches the source_string argument for occurrences of search_string.



the name of the database where the function is located.


a character string or string expression.


a string of characters that the function searches for in source_string.

position :

that the search will begin at this position in source_string.

If position is not specified, the search starts at the beginning of source_string.

If position is negative, the function counts and searches backwards from the end of source_string. position cannot have a value of zero.

occurrence :

which occurrence of search_string to find in source_string.

If occurrence is not specified, the function searches for the first occurrence.

If occurrence is greater than 1, the function searches for additional occurrences beginning with the second character in the previous occurrence. occurrence cannot be zero or a negative value.

Argument Types and Rules

Expressions passed to this function must have the following data types:

  • source_string = CHAR, VARCHAR, or CLOB
  • search_string = CHAR, VARCHAR, or CLOB
  • position = INTEGER, BIGINT, or NUMBER
  • occurrence = INTEGER, BIGINT, or NUMBER

You can also pass arguments with data types that can be converted to the above types using the implicit data type conversion rules that apply to UDFs.

Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to the required data type following the UDF implicit conversion rules, it must be explicitly cast.

If a match is found, the function returns the position (starting from 1) in the source_string for the match; otherwise the function returns 0. If any of the input arguments are NULL, the function returns NULL.

Result Type

The result data type is NUMBER.


The following query returns the result 20 indicating the position of ‘ch’ in ‘chip’. This is the second occurrence of ‘ch’ with the search starting from the second character of the source string.

Thank you for giving your valuable time to read the above information.
Follow us on 
Facebook Page KTexperts
Linkedin Page : KT EXPERTS

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Add Comment