如何在MySQL中转义单引号 [英] How to escape single quotes in MySQL

查看:1230
本文介绍了如何在MySQL中转义单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MySQL中插入由单引号或双引号组成的值.即

How do I insert a value in MySQL that consist of single or double quotes. i.e

This is Ashok's Pen.

单引号会引起问题.可能还有其他转义字符.

The single quote will create problems. There might be other escape characters.

如何正确插入数据?

推荐答案

输入非常简单:

SELECT 'This is Ashok''s Pen.';

因此,在字符串中,将每个单引号替换为两个.

So inside the string, replace each single quote with two of them.

或者:

SELECT 'This is Ashok\'s Pen.'

转义=)

这篇关于如何在MySQL中转义单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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