Can MySQL concatenate strings with ||

后端 未结 1 761
暖寄归人
暖寄归人 2020-12-10 13:15

I\'m using sqlite3 for the moment, and hence concatenation strings using the || operator.

At some later date I\'d like to shift to MySQL, and hence it

相关标签:
1条回答
  • 2020-12-10 14:07

    The || works in MySQL as well but you need to set sql_mode to PIPES_AS_CONCAT.

    Official Doc

    Demo:

    mysql> select c from tmp;
    +------+
    | c    |
    +------+
    | foo  |
    | bar  |
    +------+
    2 rows in set (0.00 sec)
    
    mysql> select c||' hi' from tmp;
    +----------+
    | c||' hi' |
    +----------+
    |        0 |
    |        0 |
    +----------+
    2 rows in set, 2 warnings (0.00 sec)
    
    mysql> set sql_mode=PIPES_AS_CONCAT;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> select c||' hi' from tmp;
    +----------+
    | c||' hi' |
    +----------+
    | foo hi   |
    | bar hi   |
    +----------+
    2 rows in set (0.00 sec)
    
    0 讨论(0)
提交回复
热议问题