DB2 string concatenation in front of field plus 0 Operation 0| | ' Field name '

Source: Internet
Author: User
Tags db2

Excerpted from http://blog.csdn.net/milife2013/article/details/8660205

DB2 string connection is the same as the Oracle database, using the "| |" Make a DB2 string connection, using the same way as the plus sign "+" in MSSQLServer. For example, execute the following SQL statement:
SELECT ' work number is ' | | fnumber| | ' The employee's name is ' | | FName from T_employee
WHERE FName is not NULL

In addition to the "| |", DB2 also supports string concatenation using the concat () function, such as executing the following SQL statement:
SELECT CONCAT (' Work number: ', fnumber) from T_employee

Unlike Oracle, if the value connected in Concat is not a string, DB2 does not attempt to type-convert but to report an error message, such as executing the following SQL statement:
SELECT CONCAT (' Age: ', Fage) from T_employee

After running, DB2 will report the following error message:
A licensed example with a compatible argument is not found with a type of "FUNCTION" named "CONCAT"

Unlike MySQL's concat () function, the DB2 concat () function supports only two parameters and does not support stitching of more than two strings, such as the following SQL statement is wrong in Oracle:
SELECT CONCAT (' Work number ', Fnumber, ' Employee name ', FName) from T_employee
WHERE FName is not NULL
After running, Oracle will report the following error message:
An authorized routine named "CONCAT" with compatible arguments is not found for type "FUNCTION"

If you want to make multiple strings of stitching, you can use multiple concat () functions nested, the above SQL can be rewritten as follows:
SELECT CONCAT (CONCAT (CONCAT (' Work number ', Fnumber), ' Employee Name '), FName) from
T_employee
WHERE FName is not NULL

DB2 string concatenation in front of field plus 0 Operation 0| | ' Field name '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.