Concatenates Oracle and MySQL strings and oraclemysql strings

Source: Internet
Author: User

Concatenates Oracle and MySQL strings and oraclemysql strings

I. MySQL

In java, we usually use the plus sign (+) to concatenate strings. in MySQL, we can also use the plus sign (+). For example:

Add test data first

CREATE TABLE test(      id INT,      name VARCHAR(10),      score FLOAT  );INSERT INTO test VALUES(1,'zhang',98);INSERT INTO test VALUES(2,'li',95);

Demo1
SELECT NAME+'hello' FROM test;
Execution result:


MySQL will try to convert the field values at both ends of the plus sign to the numeric type. If the conversion fails, the field value is regarded as 0.

Demo2

SELECT score,score+5 FROM test;
Execution result:

From the above, we can see that "+" is actually an operator. To concatenate strings in MySQL, you must use the CONCAT function,

The CONCAT function supports one or more parameters. The parameter type can be string or non-string. For non-string parameters, MySQL will try

Convert it to the string type. The CONCAT function concatenates all parameters into a string in the order of parameters as the return value.


Demo3

SELECT CONCAT(NAME,'-hello',' good') FROM test;
Execution result:

MySQL also provides another String concatenation function CONCAT_WS,

CONCAT_WS can add the specified separator between the strings to be spliced. The first parameter is the delimiter to be set,

The remaining parameters are the string values to be spliced.


Demo4

SELECT CONCAT_WS ('-', NAME, '', score) FROM test;
Execution result:



Ii. Oracle

Concatenate strings using "|" in Oracle


Demo5

select name||'hello' from test;
Execution result:


In addition to "|", Oracle also supports String concatenation using the CONCAT () function.


Demo6

select concat(name,score) from test;
Execution result:

If the connected value in CONCAT is not a string, Oracle will try to convert it to a string,

Unlike MySQL's CONCAT () function, Oracle's CONCAT () function only supports two parameters and does not support concatenation of two or more strings.


Author: itmyhome

Source: http://blog.csdn.net/itmyhome1990/article/details/41848229



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.