首页 > 解决方案 > sql 存储过程 Quotes()

问题描述

我需要在存储过程中生成这样的字符串。

select case when Sex like '%' then 'Person' end as Sex from tableName;

在存储过程中,我已经像这样生成了。

select case when Sex like quote(%) then quote(Person) end as Sex from tableName;

我得到的错误是

    Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%) then quote(Person) end as Sex from tableName' at line 1   0.000 sec

我的 MariaDB 版本是“10.3.16-MariaDB”

请帮助解决此问题。

标签: mysqlsqlstored-proceduresquotes

解决方案


您没有在第二个查询中引用文字。尝试:

SELECT CASE
         WHEN sex LIKE quote('%') THEN
           quote('Person')
       END AS sex
       FROM tablename;

但这对文字没有太大意义,quote()因为您已经必须转义其中的任何特殊字符。所以申请quote()是多余的。


推荐阅读