Chapter 3 DBMS Reference Guide
Variables have a syntax that can force a format on their values. Typical uses are as follows:
You embed formatting options in variable syntax as follows:
%[[?][-][width][.[-]precision][c][H][F][U|L][T][M][q][Q]:]<varname>%
The variable formatting options are the following:
| option | Description |
|---|---|
| ? | Mandatory field, if a null value is returned the translate call fails |
| n (where n is an integer) | Blanks or zeros added to the right to fill the width and justify the output to the left |
| -n | Blanks or zeros added to the left to fill the width and justify the output to the right |
| width | Copies the specified minimum number of characters to the output buffer |
| .[-]precision | Copies the specified maximum number of characters to the output buffer |
| .L | Lower-case characters |
| .U | Upper-case characters |
| .F | Combined with L and U, applies conversion to first character |
| .T | Leading and trailing white space trimmed from the variable |
| .H | Converts number to hexadecimal |
| .c | Upper-case first letter and lower-case next letters |
| .n | Truncates to n first characters |
| .-n | Truncates to n last characters |
| M | Extracts a portion of the variable name, this option uses the width and precision parameters to identify the portion to extract |
| q | Enquotes the variable (single quotes) |
| Q | Enquotes the variable (double quotes) |
You can combine format codes. For example, %.U8:CHILD% formats the code of the child table with a maximum of eight uppercase letters.
The following examples show format codes embedded in the variable syntax for the constraint name template for primary keys, using a table called CUSTOMER_PRIORITY:
| Format | Use |
|---|---|
| .L | Lower-case characters.
Example: PK_%.L:TABLE% Result: PK_customer_priority |
| .Un | Upper-case characters + left justify variable text to fixed length where n is the number of characters.
Example: PK_%.U12:TABLE% Result: PK_CUSTOMER_PRI |
| .T | Trim the leading and trailing white space from the variable.
Example: PK_%.T:TABLE% Result: PK_customer_priority |
| .n | Maximum length where n is the number of characters.
Example: PK_%.8:TABLE% Result: PK_Customer |
| -n | Pad the output with blanks to the right to display a fixed length where n is the number of characters.
Example: PK_%-20:TABLE% Result: PK_ Customer_priority |
| M | Extract a portion of a variable.
Example: PK%3.4M:TABLE% Result: PK_CUST |
| Copyright (C) 2007. Sybase Inc. All rights reserved. |
| |