This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
dev:sql:functions:position [2010/07/02 08:36] tdo |
dev:sql:functions:position [2016/06/28 22:38] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| {{page>:top_add&nofooter&noeditbtn}} | {{page>:top_add&nofooter&noeditbtn}} | ||
| - | <html><div align="center"><span style="color:red">DRAFT</span></div></html> | ||
| - | ====== Omnidex SQL Function: POSITION ====== | ||
| {{page>:sql_bar&nofooter&noeditbtn}} | {{page>:sql_bar&nofooter&noeditbtn}} | ||
| + | ====== Omnidex SQL Function: POSITION ====== | ||
| ===== Description ===== | ===== Description ===== | ||
| - | The POSITION function finds the position of a search_string in a target_string. | + | The POSITION function finds the position of a search_string in a target_string. If the target_string is of length zero, the result is 1. If the search_string occurs as a substring within the target_string, the character position where the search_string first occurs is returned. If neither of these conditions is true, the result is 0. |
| - | If the target_string is of length zero, the result is 1. | + | String comparisons are case-sensitive. Use the UPPER and LOWER functions around the search_string and the target_string to produce a case-insensitive search. |
| - | If the search_string occurs as a substring within the target_string, the character position where the search_string first occurs is returned. If neither of these conditions is true, the result is 0. | + | This function returns an INTEGER datatype. |
| - | The return data type is a 4-byte INTEGER. | + | ===== Syntax ===== |
| - | String comparisons are case-sensitive. Use the UPPER and LOWER functions around the search_string and the target_string to produce a case-insensitive search. | + | POSITION( search_expression IN target_expression) |
| - | ===== Syntax ===== | + | == search_expression === |
| - | POSITION( search_string IN target_string) | + | |
| - | == search_string === | + | Any expression that returns a character-class datatype to be used as the search criteria. Examples of expressions are columns, concatenations of columns, literal strings and functions that return a character datatype. |
| - | Any valid text string enclosed in single quotes or a column_spec or an expression such as a function that resolves to a text string. The search_string is the string of interest that is being search for in the target_string. | + | |
| - | == IN == | + | == target_expression == |
| - | Required. | + | |
| - | == target_string == | + | Any expression that returns a character-class datatype to be used as the search target. Examples of expressions are columns, concatenations of columns, literal strings and functions that return a character datatype. |
| - | Any column_spec or valid text string enclosed in single quotes or an expression such as a function that resolves to a text string. The target_string in which to search for the occurance of the search_string. | + | |
| ===== Example ===== | ===== Example ===== | ||
| - | ==== Example 1 ==== | + | ==== Example 1: Column ==== |
| - | <code SQL> | + | |
| - | select company, | + | |
| - | position(upper('sys') IN upper(customers.company)) | + | |
| - | from customers where company='systems' | + | |
| - | Company Position | + | <code> |
| - | -------- --------------- | + | > select name, position('.' in name) pos from individuals; |
| - | Camco Systems 7 | + | |
| - | SoftSys Corp 5 | + | NAME POS |
| + | -------------------------------------------------- ----------- | ||
| + | MS. MARY LEWIS 3 | ||
| + | MRS. ALICE R TOLLIVER 4 | ||
| + | MR. SIDNEY K TOLLIVER 3 | ||
| + | MRS. JENNIFER J HOPKINS 4 | ||
| + | MR. CHARLIE HOPKINS 3 | ||
| + | MS. KIMBERLY BLUE 3 | ||
| + | KATHLEEN TUCKER 0 | ||
| </code> | </code> | ||
| + | |||
| + | ==== Example 2: Complex expression ==== | ||
| + | |||
| + | The following example removes the salutation from the name. | ||
| + | |||
| + | <code> | ||
| + | > select trim( | ||
| + | >> substring(NAME | ||
| + | >> from position('.' in NAME) + 1 | ||
| + | >> for $column_length(NAME) - position('.' in NAME))) nme | ||
| + | >> from INDIVIDUALS; | ||
| + | |||
| + | NME | ||
| + | -------------------------------------------------- | ||
| + | MARY LEWIS | ||
| + | ALICE R TOLLIVER | ||
| + | SIDNEY K TOLLIVER | ||
| + | JENNIFER J HOPKINS | ||
| + | CHARLIE HOPKINS | ||
| + | KIMBERLY BLUE | ||
| + | KATHLEEN TUCKER | ||
| + | </code> | ||
| + | ====== Additional Resources ====== | ||
| + | |||
| + | See also: | ||
| + | {{page>dev:sql:functions:see_also_string&nofooter&noeditbtn&noheader}} | ||
| + | |||
| + | |||
| {{page>:bottom_add&nofooter&noeditbtn}} | {{page>:bottom_add&nofooter&noeditbtn}} | ||