本文内容来自YashanDB官网,原文内容请见 https://www.yashandb.com/newsinfo/7323369.html?templateId=171...
前言
MySQL应用使用的SQL的Where条件存在FIND\_IN\_SET,无法在YashanDB直接执行,需要改写。本文探讨不兼容的原因,并给出改写手段。
问题
SQL示例
MySQL执行成功
<p><span>mysql> select c1 from t1 where find_in_set(c2,'</span><span>a,b</span><span>,c');</span></p><p><span>+------+</span></p><p><span>| c1 |</span></p><p><span>+------+</span></p><p><span>| 1 |</span></p><p><span>+------+</span></p><p><span>1 row in set (0.00 sec)</span></p> |
<p><span>SQL> select c1 from t1 where find_in_set(c2,'</span><span>a,b</span><span>,c');</span></p><p><span>[</span><span>1:25]YAS</span><span>-04336 boolean expression expected</span></p> |
<p><span>mysql> select find_in_set('b','</span><span>a,b</span><span>,c') from dual;</span></p><p><span>+--------------------------+</span></p><p><span>| find_in_set('b','</span><span>a,b</span><span>,c') |</span></p><p><span>+--------------------------+</span></p><p><span>| 2 |</span></p><p><span>+--------------------------+</span></p><p><span>1 row in set (0.00 sec)</span></p><p><span> </span></p><p><span>mysql> select find_in_set('d','</span><span>a,b</span><span>,c') from dual;</span></p><p><span>+--------------------------+</span></p><p><span>| find_in_set('d','</span><span>a,b</span><span>,c') |</span></p><p><span>+--------------------------+</span></p><p><span>| 0 |</span></p><p><span>+--------------------------+</span></p><p><span>1 row in set (0.00 sec)</span></p><p><span> </span></p><p><span>mysql> select 1 from dual where 2;</span></p><p><span>+---+</span></p><p><span>| 1 |</span></p><p><span>+---+</span></p><p><span>| 1 |</span></p><p><span>+---+</span></p><p><span>1 row in set (0.00 sec)</span></p><p><span> </span></p><p><span>mysql> select 1 from dual where 0;</span></p><p><span>Empty set (0.00 sec)</span></p> |
<p><span>SQL> select find_in_set('b','</span><span>a,b</span><span>,c') from dual;</span></p><p><span>FIND_IN_</span><span>SET(</span><span>'B','A,B</span></p><p><span>--------------------</span></p><p><span> 2</span></p><p><span> </span></p><p><span>1 row fetched.</span></p><p><span>SQL> select find_in_set('d','</span><span>a,b</span><span>,c') from dual;</span></p><p><span>FIND_IN_</span><span>SET(</span><span>'D','A,B</span></p><p><span>--------------------</span></p><p><span> 0</span></p><p><span> </span></p><p><span>1 row fetched.</span></p><p><span>SQL> select 1 from dual where 2;</span></p><p><span>[</span><span>1:26]YAS</span><span>-04336 boolean expression expected</span></p><p><span>SQL> select 1 from dual where 0;</span></p><p><span>[</span><span>1:26]YAS</span><span>-04336 boolean expression expected</span></p> |
<p><span>SQL> select c1 from t1 where 0 < find_in_set(c2,'</span><span>a,b</span><span>,c');</span></p><p><span> C1</span></p><p><span>------------</span></p><p><span> 1</span></p><p><span>1 row fetched.</span></p> |
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。