Skip to main content

STRING

A function that converts and concatenates expressions into a string.

Synopsis

STRING(string1[,string2][,...][,stringn])

Arguments

Argument Description
string An expression, which can be a field name, a string literal, a numeric, or the result of another function, where the underlying data type can be represented as any character type (such as CHAR or VARCHAR2). If a field name is specified, the logical value is used.

Description

STRING converts one or more strings to the STRING format, and then concatenates these strings into a single string. No case transformation is performed.

STRING converts numerics to their canonical form before string conversion. It therefore performs arithmetic operations, removes leading and trailing zeros and leading plus signs from numbers.

If one of the string arguments is NULL, STRING returns NULL. If one of the string arguments is the empty string (''), STRING concatenates the other arguments. STRING retains whitespace.

You can use the %SQLSTRING function to convert a data value for case-sensitive string comparison, or the %SQLUPPER function to convert a data value for not case-sensitive string comparison.

Examples

In the following Embedded SQL example, STRING concatenates three substrings into a single string. The example shows the handling of blank spaces, the empty string, and NULL:

   &sql(SELECT STRING('a','b','c'),
               STRING('a',' ','c'),
               STRING('a','','c'),
               STRING('a',NULL,'c')
        INTO :w,:x,:y,:z)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"Resulting string is:",w
     WRITE !,"Resulting string is:",x
     WRITE !,"Resulting string is:",y
     WRITE !,"Resulting string is:",z }

In the following Embedded SQL example, STRING converts numerics into a string. All of these STRING functions return the string '123':

   &sql(SELECT STRING(123),
               STRING(+00123.00),
               STRING('1',23),
               STRING(1,(10*2)+3)
        INTO :w,:x,:y,:z)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"Resulting string is:",w
     WRITE !,"Resulting string is:",x
     WRITE !,"Resulting string is:",y
     WRITE !,"Resulting string is:",z }

In the following Embedded SQL example, STRING retrieves sample data from fields and concatenates it into a string:

   &sql(SELECT STRING(Name,Age)
        INTO :x
        FROM Sample.Person)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"Resulting string is:",x }

See Also

%STRING %SQLUPPER %SQLSTRING STR

FeedbackOpens in a new tab