>>-POSITION-----------------------------------------------------> >--(--+-search-string--IN--source-string--USING--+-CODEUNITS16-+-+--)->< | +-CODEUNITS32-+ | | '-OCTETS------' | '-search-string--,--source-string--,--+-CODEUNITS16-+------' +-CODEUNITS32-+ '-OCTETS------'
The schema is SYSIBM.
The POSITION function returns the starting position of the first occurrence of one string (called the search-string) within another string (called the source-string). If search-string is not found and neither argument is null, the result is zero. If the search-string is found, the result is a number from 1 to the actual length of source-string, expressed in the string unit that is explicitly specified. The search is done using the collation of the database, unless search-string or source-string is defined as FOR BIT DATA, in which case the search is done using a binary comparison.
If source-string has an actual length of 0, the result of the function is 0. If search-string has an actual length of 0 and source-string is not null, the result of the function is 1.
These rules are similar to those that are described for pattern-expression for the LIKE predicate.
If a string unit is specified as CODEUNITS16 or CODEUNITS32, and search-string or source-string is a binary string or bit data, an error is returned (SQLSTATE 428GC). If a string unit is specified as OCTETS and search-string and source-string are binary strings, an error is returned (SQLSTATE 42815).
If a locale-sensitive UCA-based collation is used for this function, then the CODEUNITS16 option offers the best performance characteristics.
For more information about CODEUNITS16, CODEUNITS32, and OCTETS, see "String units in built-in functions" in "Character strings".
The first and second arguments must have compatible string types. For more information on compatibility, see "Rules for string conversions". In a Unicode database, if one string argument is character (not FOR BIT DATA) and the other string argument is graphic, then the search-string is converted to the data type of the source-string for processing. If one argument is character FOR BIT DATA, the other argument must not be graphic (SQLSTATE 42846).
The result of the function is a large integer. If any argument can be null, the result can be null; if any argument is null, the result is the null value.
Examples:
SELECT RECEIVED, SUBJECT, POSITION('GOOD BEER', NOTE_TEXT, OCTETS)
FROM IN_TRAY
WHERE POSITION('GOOD BEER', NOTE_TEXT, OCTETS) <> 0
SET :LOCATION = POSITION(
'ß', 'Jürgen lives on Hegelstraße', CODEUNITS32
)
The value of host variable LOCATION is set to 26. SET :LOCATION = POSITION(
'ß', 'Jürgen lives on Hegelstraße', OCTETS
)
The value of host variable LOCATION is set to 27.'&' | 'N' | '~' | 'A' | 'B' | |
---|---|---|---|---|---|
UTF-8 | X'F09D849E' | X'4E' | X'CC83' | X'41' | X'42' |
UTF-16BE | X'D834DD1E' | X'004E' | X'0303' | X'0041' | X'0042' |
SELECT POSITION('N', UTF8_VAR, CODEUNITS16),
POSITION('N', UTF8_VAR, CODEUNITS32),
POSITION('N', UTF8_VAR, OCTETS)
FROM SYSIBM.SYSDUMMY1
returns the values 3,
2, and 5, respectively. SELECT POSITION('B', UTF16_VAR, CODEUNITS16),
POSITION('B', UTF16_VAR, CODEUNITS32),
POSITION('B', UTF16_VAR, OCTETS)
FROM SYSIBM.SYSDUMMY1
returns the values 6,
5, and 11, respectively.SET :LOCATION = POSITION('Brown', 'The quick brown fox', CODEUNITS16)
The
value of the host variable LOCATION is set to 11.