23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SUBSTRING (ODBC compatible)<br />

Syntax<br />

SUBSTRING (ODBC compatible)<br />

Returns the substring of the character string corresponding to the first argument starting at<br />

start_pos and length characters long. If the third argument length is not specified, the<br />

substring starting at start_pos up to the end of char_expression is returned.<br />

SUBSTRING ( char_expression, start_pos [ , length ] )<br />

Example This example illustrates the SUBSTRING function:<br />

SELECT last_name, '(', SUBSTRING (phone, 1, 3) , ')',<br />

SUBSTRING (phone, 4, 3), '-',<br />

SUBSTRING (phone, 7, 4)<br />

FROM customer ;<br />

Notes • The first argument must be of type CHARACTER. It can be any meaningful character value<br />

(for example, a literal expression, database column, or parameter).<br />

• The second argument must be of type INTEGER. It indicates the starting position from<br />

which the substring result is extracted.<br />

• The third argument, if specified, must be of type INTEGER. It indicates the number of<br />

characters the substring function will extract.<br />

• The values for specifying position in the character string start from 1. The first character<br />

in a string is at position 1, the second character is at position 2, and so on.<br />

• The result is of type CHARACTER.<br />

• If any of the argument expressions evaluate to NULL, the result is NULL.<br />

• char_expression and the result can contain multi-byte characters.<br />

• If the value of start_pos is:<br />

– Smaller than 0, the function returns a “Bad argument” error<br />

– Bigger than the actual length of the string value, the function returns an empty zero<br />

length substring<br />

• If the value of length is:<br />

– Smaller than 0, the function returns a “Bad argument” error.<br />

– Bigger than the actual length of the substring (from start_pos to the end of the<br />

literal), the function returns the substring from start_pos to the end of the literal.<br />

– Bigger than the actual length of the substring (from start_pos up to the end of the<br />

column’s row data), the function returns the substring from the start_pos to the end<br />

of the column’s row data. The function returns this, even when the substring result<br />

exceeds the column’s <strong>SQL</strong> width.<br />

127

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!