This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dev:sql:functions:lpad [2009/12/07 14:24] tdo created |
dev:sql:functions:lpad [2010/07/09 20:09] els |
||
---|---|---|---|
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: CASE ====== | ||
{{page>:sql_bar&nofooter&noeditbtn}} | {{page>:sql_bar&nofooter&noeditbtn}} | ||
+ | ====== Omnidex SQL Function: $LPAD ====== | ||
===== Description ===== | ===== Description ===== | ||
- | The $LPAD function adds pad characters to the left of a character string up to the specified total length. | + | Pad the string on the left with spaces or the named character. If the string is already padded, as happens with a CHARACTER datatype, the string must first be trimmed using the TRIM function. |
+ | |||
+ | This function returns a C STRING datatype. | ||
- | The return data type is C STRING of length specified in the n parameter + 1. | ||
===== Syntax ===== | ===== Syntax ===== | ||
- | $LPAD( <column_spec | 'string'> , return_length [ ,pad_character ] ) | ||
- | == < column_spec, string > == | + | $LPAD( character_expression, num_characters [, pad_character] ) |
- | Required. The string to be "padded". If the length of the string is longer than n, the portion of the string that fits into n is returned. | + | |
- | == return_length == | + | == character_expression == |
- | Required. n is the total length of the return value ( 0 < n <= 255) | + | |
- | == pad_character == | + | Required. Any expression that returns a character-class datatype. Examples of expressions are columns, concatenations of columns, literal strings and functions that return a character datatype. |
- | Optional. pad evaluates to a single character. The default is the space character. | + | |
- | ===== Example ===== | + | |
- | ==== Example 1 ==== | + | |
- | <code SQL> | + | |
- | SELECT | + | |
- | $LPAD(COMPANY, 45, '*'), | + | |
- | $RPAD(COMPANY, 45, '#') | + | |
- | FROM CUSTOMERS | + | |
- | WHERE COMPANY='SYSTEMS' | + | |
- | *****Dynamic Information Systems Corporation | + | == num_characters == |
- | Dynamic Information Systems Corporation ##### | + | |
+ | Required. The number of characters to be returned from the function, with the left-most characters padded with spaces or the named character. | ||
+ | |||
+ | == pad_character == | ||
+ | |||
+ | Optional. The character to be used to pad the string. If this parameter is omitted, then a space is used as the pad character. | ||
+ | |||
+ | ===== Examples ===== | ||
+ | ==== Example: Column ==== | ||
+ | |||
+ | In this example, the name must first be trimmed and since it is already padded with spaces. | ||
+ | |||
+ | <code> | ||
+ | > SELECT $lpad(trim(name), 40, '.') nme FROM individuals; | ||
+ | |||
+ | NME | ||
+ | ---------------------------------------- | ||
+ | ..........................MS. MARY LEWIS | ||
+ | ...................MRS. ALICE R TOLLIVER | ||
+ | ...................MR. SIDNEY K TOLLIVER | ||
+ | .................MRS. JENNIFER J HOPKINS | ||
+ | .....................MR. CHARLIE HOPKINS | ||
+ | .......................MS. KIMBERLY BLUE | ||
+ | .........................KATHLEEN TUCKER | ||
</code> | </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}} |