Oracle and MySQL string concatenation

Source: Internet
Author: User

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

Related Article

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.