WRITE LINE statement (Character string output to a file)
Function
Outputs the character string in a specified value expression to a file.
Format
WRITE LINE value-expression |
Operands
Specifies the value expression to be output to the file.
The following rules apply to the value expression:
- The following items can be specified in value-expression:
- Literals
- USER
- SQL variables or SQL parameters
- Concatenation operations
- Scalar functions
- Function calls
- CASE expressions
- CAST specifications
- SQLERRM_OF_LAST_CONDITION
- The data type of the value expression must be a character data type (CHAR or VARCHAR), a national character data type (NCHAR or NVARCHAR), or a mixed character data type (MCHAR or MVARCHAR).
- If the data type of the result of the value expression is character data, the character set used to output the character data to a file is the character set specified in the value expression.
- The value expression is output to the location specified by PDWRTLNPATH in the client environment definition. Use PDWRTLNFILSZ in the client environment definition to specify the maximum size of the file to which the value expression is to be output. For details about PDWRTLNPATH and PDWRTLNFILSZ, see the manual HiRDB Version 9 UAP Development Guide.
- The line-terminating code of the environment on the HiRDB server side is appended to the end of the character string in the value expression. The line-terminating code varies from one HiRDB server operating system to another. If the value of the value expression exceeds the size specified in the PDWRTLNCOMSZ client environment definition, for the line-terminating code on the HiRDB server side to be appended at the end, the trailing end of the value expression character expression is deleted so that the character string fits in the size specified in PDWRTLNCOMSZ, and the line-terminating code is appended. For details about PDWRTLNCOMSZ, see the HiRDB Version 9 UAP Development Guide.
The following table lists the line-terminating codes that are appended on the HiRDB server side.
Table 7-4 Line-terminating codes that are appended on the HiRDB server side
HiRDB server OS | Appended line-terminating code |
---|
HP-UX | NL(X'0a') |
Solaris | NL(X'0a') |
AIX | NL(X'0a') |
Linux | NL(X'0a') |
Windows | CR(X'0d') + NL(X'0a') |
- If the value of the value expression is the null value, the line-terminating code is not output to the file.
- A subquery cannot be specified in a value expression.
Common rules
- The WRITE LINE statement can be specified in SQL procedures and triggers; it cannot be specified in an SQL function.
- The WRITE LINE statement cannot be executed without specification of the PDWRTLNFILSZ client environment definition.
Example
Convert the SQL parameter fromdate of the date data type into a character string and output the results to a file:
CREATE PROCEDURE proc_1(IN fromdate DATE)
BEGIN
WRITE LINE 'fromdate='||char(fromdate);
END;