如何将包含单引号的字符串值插入字符串类型表列? [英] How can I insert string value including single quote into a string type table column?

查看:87
本文介绍了如何将包含单引号的字符串值插入字符串类型表列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将包含单引号的字符串值插入字符串类型表列?

How can I insert string value including single quote into a string type table column?

推荐答案

使用''(两个单引号)。例如:想要保存彼得,那么它应该是彼得的。
Use '' (two single quotes). Ex: want to save Peter's then it should be Peter''s.


请看这个

please see this
Put quite simply:

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

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

Or:

SELECT 'This is Ashok\'s Pen.'






从来都不是一个好习惯在数据库中插入单引号',因为它会导致SQL注入。



无论如何你仍然想要这样做....可以查看下面



Hi,

It is never a good practice to insert Single Quote " ' " with your data in database as it leads to SQL Injections.

Anyway if you still want to do it....can check below

insert into your_Table (your_col) values ('he''s')









按照你的意见检查下面









As per your comments check below


DECLARE @strVar VARCHAR(100)
SET @strVar='hi''s'
print(@strVar)











希望这会对你有所帮助。





< br $> b $ b



干杯。






Hope this will be helpful to you.





Cheers.


这篇关于如何将包含单引号的字符串值插入字符串类型表列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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