将具有 '(撇号)的文本插入 SQL 表的方法 [英] Way to insert text having ' (apostrophe) into a SQL table

查看:36
本文介绍了将具有 '(撇号)的文本插入 SQL 表的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试执行以下 SQL 命令时,出现 sql 错误.

While I was trying the following SQL command , I got sql error.

INSERT INTO exampleTbl VALUES('he doesn't work for me')

where 不包含撇号.

where doesn't contain the apostrophe.

在 SQL 表中插入带有 '(撇号)的文本的方法是什么.

What is the way to insert text having ' (apostrophe) into a SQL table.

推荐答案

在 SQL 中,这样做的方法是将撇号加倍:

In SQL, the way to do this is to double the apostrophe:

'he doesn''t work for me'

如果您以编程方式执行此操作,您应该使用接受参数并为您转义它们的 API,例如准备好的语句或类似的,而不是转义并使用字符串连接来组装查询.

If you are doing this programmatically, you should use an API that accepts parameters and escapes them for you, like prepared statements or similar, rather that escaping and using string concatenation to assemble a query.

这篇关于将具有 '(撇号)的文本插入 SQL 表的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆