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)
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)
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)
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!