- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How does the precedence of || operator depend on PIPES_AS_CONCAT SQL mode?
As we know that in MySQL by default || operator is a logical OR operator but it depends upon PIPES_AS_CONCAT SQL mode. If PIPES_AS_CONCAT SQL mode is enabled, then || operator works as string concatenation. At that time its precedence would be between ^ and the unary operator. 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)
The result set of the above query shows that || works as OR operator that is why the output is 1 for true.
mysql> Set SQL_MODE = 'PIPES_AS_CONCAT'; Query OK, 0 rows affected (0.10 sec)
After enabling the PIPES_AS_CONCAT SQL mode, || works as the synonym of CONCAT() function i.e. string concatenation function. It is shown in the following result set −
mysql> Select @C||@D; +----------------+ | @C||@D | +----------------+ | tutorialspoint | +----------------+ 1 row in set (0.00 sec)
Advertisements