Realization of string connection in Oracle

  • 2021-07-18 09:16:56
  • OfStack

Like other database systems, Oracle string concatenation uses "" for string splicing in the same way as the plus sign "+" 1 in MSSQLServer.

For example, execute the following SQL statement:


SELECT ' Job number is '||FNumber||' The name of the employee of is '||FName FROM T_Employee 
WHERE FName IS NOT NULL 


In addition to "," Oracle also supports string splicing using the CONCAT () function, such as executing the following SQL statement:
SELECT CONCAT ('job number: ', FNumber) FROM T_Employee

If the value of the connection in CONCAT is not a string, Oracle attempts to convert it to a string, such as executing the following SQL statement:
SELECT CONCAT ('Age:', FAge) FROM T_Employee

Unlike the CONCAT () function of MYSQL, the CONCAT () function of Oracle only supports two arguments, and does not support the splicing of more than two strings. For example, the following SQL statement is wrong in Oracle:
SELECT CONCAT ('work number is', FNumber, 'employee name is', FName) FROM T_Employee
WHERE FName IS NOT NULL
After running, Oracle will report the following error message:
Invalid number of parameters

If you want to splice multiple strings, you can use multiple CONCAT () functions nested. The above SQL can be rewritten as follows:


SELECT CONCAT(CONCAT(CONCAT(' Job number is ',FNumber),' The name of the employee of is '),FName) FROM 
T_Employee 
WHERE FName IS NOT NULL 

Related articles: