mysql - 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”
请帮助解决此问题。
解决方案
您没有在第二个查询中引用文字。尝试:
SELECT CASE
WHEN sex LIKE quote('%') THEN
quote('Person')
END AS sex
FROM tablename;
但这对文字没有太大意义,quote()
因为您已经必须转义其中的任何特殊字符。所以申请quote()
是多余的。
推荐阅读
- c# - How to call shell script in C# vs VB.Net
- api - error: A value of type 'LocationModel' can't be returned from method 'getLocation' because it has a return type of 'List
' - python - Images Aren't Loading When Launching Website With Heroku. How Do I Fix This?
- unity3d - Discord Unity SDK showing still playing, yet it is closed
- sql - 我是 SQL Server 的新手。我创建了一个函数,它的作用类似于 charindex
- python - 如何从 Markdown 文件创建树?
- jquery - 在 Django 中使用 jQuery 和 AJAX 动态更新 Web API 结果
- twos-complement - 二进制补码加法。-48 - 23. 是否必须使用 8 位表示?
- react-native - Redux Saga action 异步操作调用了一次但触发了两次
- java - Maven 上的未知生命周期阶段