Home > Database > Mysql Tutorial > body text

'How does the precedence of the || operator depend on the PIPES_AS_CONCAT SQL mode?'

PHPz
Release: 2023-08-23 13:33:14
forward
690 people have browsed it

How does the precedence of the || operator depend on the PIPES_AS_CONCAT SQL mode?

We know that in MySQL, the || operator is a logical OR operator by default, but it depends on the PIPES_AS_CONCAT SQL mode. If PIPES_AS_CONCAT SQL mode is enabled, the || operator will work as a string concatenation operator. At this point, its precedence will be between ^ and the unary operator. The following example will make it understand −

mysql> Set @C='tutorials';
Query OK, 0 rows affected (0.00 sec)

mysql> Set @D='point';
Query OK, 0 rows affected (0.00 sec)

mysql> Select @C||@D;
+--------+
| @C||@D |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)
Copy after login

The result set of the above query shows || as OR operator, that’s why the output is 1 which means true.

mysql> Set SQL_MODE = 'PIPES_AS_CONCAT';
Query OK, 0 rows affected (0.10 sec)
Copy after login

After enabling PIPES_AS_CONCAT SQL mode, || is used as a synonym for the CONCAT() function, that is, the string connection function. It is shown in the following result set −

mysql> Select @C||@D;
+----------------+
| @C||@D         |
+----------------+
| tutorialspoint |
+----------------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of 'How does the precedence of the || operator depend on the PIPES_AS_CONCAT SQL mode?'. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template