First, MySQL
in Java we usually use the plus "+" to achieve the concatenation of strings, MySQL can also use "+" to achieve, such as:
Add test Data First
CREATE TABLE Test ( ID INT, name VARCHAR, score FLOAT ); INSERT into Test VALUES (1, ' Zhang ', 98); I Nsert into Test VALUES (2, ' Li ', 95);
Demo1
SELECT name+ ' hello ' from test;
Execution Result:
MySQL attempts to convert the field values at both ends of the plus sign to a number type, and if the conversion fails, the field value is 0
Demo2
SELECT score,score+5 from Test;
Execution Result:
from the above can be seen as "+" is actually an operator, in MySQL string concatenation to use the CONCAT function,
The CONCAT function supports one or more parameters, parameter types can be string types or non-string types, and for non-string type arguments, MySQL will attempt to
Converting it to a string type, the Concat function will stitch all parameters into a string as a return value in the order of the arguments.
Demo3
SELECT CONCAT (NAME, '-hello ', ' good ') from test;
Execution Result:
Another function Concat_ws for string stitching is provided in MySQL ,
Concat_ws can add the specified delimiter between the strings to be stitched, the first parameter is the delimiter to be set,
The remaining parameters are the string values to be spliced
Demo4
SELECT concat_ws ('-', NAME, ' test ', score) from test;
Execution Result:
Second, Oracle
Using "| |" in Oracle Concatenation of strings
Demo5
Select Name| | ' Hello ' from test;
Execution Result:
In addition to the "| |", Oracle also supports string concatenation using the concat () function
Demo6
Select Concat (name,score) from test;
Execution Result:
If the value connected in Concat is not a string, Oracle attempts to convert it to a string.
Unlike MySQL's concat () function, Oracle's CONCAT () function supports only two parameters and does not support stitching of more than two strings.
Itmyhome
Source: http://blog.csdn.net/itmyhome1990/article/details/41848229
Oracle and MySQL string concatenation