SQL 查询访问中带有撇号的文本 [英] SQL to Query text in access with an apostrophe in it

查看:33
本文介绍了SQL 查询访问中带有撇号的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Access 数据库中的列名 tblStudents 中查询名称 (Daniel O'Neal),但是 Access 报告语句出现语法错误:

I am trying to query a name (Daniel O'Neal) in column names tblStudents in an Access database, however Access reports a syntax error with the statement:

Select * from tblStudents where name like 'Daniel O'Neal'

由于名称中的撇号.

我该如何克服?

推荐答案

你可以通过加倍来逃避 ',所以:

You escape ' by doubling it, so:

Select * from tblStudents where name like 'Daniel O''Neal' 

请注意,如果您接受来自用户输入的Daniel O'Neal",则损坏的引用是一个严重的安全问题.您应该始终清理字符串或使用参数化查询.

Note that if you're accepting "Daniel O'Neal" from user input, the broken quotation is a serious security issue. You should always sanitize the string or use parametrized queries.

这篇关于SQL 查询访问中带有撇号的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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