Returns the substring of a character string, starting from the position specified by start_pos and ending before the specified character.

Syntax

PREFIX ( char_expression , start_pos , char_expression )

Parameters

char_expression

Evaluates to a character string, typically a character‑string literal or column name. If the expression evaluates to NULL, PREFIX returns NULL.

start_pos

Evaluates to an integer value. PREFIX searches the string specified in the first argument starting at that position. A value of 1 indicates the first character of the string.

char_expression

Evaluates to a single character. PREFIX returns the substring that ends before that character. If PREFIX does not find the character, it returns the substring beginning at start_pos, to the end of the string. If the expression evaluates to more than one character, PREFIX ignores all but the first character.

Notes

Each char_expression and the result can contain multi‑byte characters. The start_pos argument specifies the character position, not a byte position. Character comparisons are case sensitive and are determined by sort weights in the collation table in the database.

Example

The following example shows one way to use the PREFIX function:

create table prefix_table 
     (
     colstring varchar(20),
     colchar char(1)
     );
 insert into prefix_table values ('string.with.dots', '.');
 insert into prefix_table values ('string-with-dashes', '-');
 select colstring, colchar, prefix(colstring, 1, '.') from prefix_table;
COLSTRING             COLCHAR               prefix(COLSTRING,1,.)  
--------------------- --------------------- ---------------------- 
string.with.dots      .                     string                 
string-with-dashes    -                     string-with-dashes     
  select colstring, colchar, prefix(colstring, 1, colchar) from prefix_table;
 COLSTRING             COLCHAR               prefix(COLSTRING,1,COLCHAR)  
--------------------- --------------------- ---------------------------- 
string.with.dots      .                     string                       
string-with-dashes    -                     string                       
  select colstring, colchar, prefix(colstring, 1, 'X') from prefix_table;
 COLSTRING             COLCHAR               prefix(COLSTRING,1,X)  
--------------------- --------------------- ---------------------- 
string.with.dots      .                     string.with.dots       
string-with-dashes    -                     string-with-dashes 

Compatibility

Progress extension