找回密码
 立即注册
搜索
热搜: 活动 交友
查看: 807|回复: 1

sql怎么使用escape标识转义符

[复制链接]
发表于 2025-2-6 15:39:23 | 显示全部楼层 |阅读模式
在处理sql时,遇到baiinsert 或update 的参数中含有特殊字符“&”,下划线“du_”, 单引号" ' "等时,要zhi做转义处理。
例:插入特殊字元dao'&'
update userinfo set pageurl='myjsp?page=1&pagesize=10' where id='test'
两个办法:
1) update userinfo set pageurl='myjsp?page=1'||'&'||'pagesize=10' where id='test'
2) update userinfo set pageurl='myjsp?page=1'||chr(38)||'pagesize=10' where id='test'
注:其中 || 是连字符, chr(38)跟ASCII的字符转码是一致的。
例:搜索以“QA_”开头的数据 :
select CODE from CNT_CODELIST where code like 'QA_%'
结果为:QA_OFFICER_1,QA_OFFICER_2,QA112
不符合,必须把下划线转义
select CODE from CNT_CODELIST where code like 'QA/_%'escape '/'
结果为:QA_OFFICER_1,QA_OFFICER_2
转义字符 % 处理手法如&
转义字符 ’单引号 在PL/SQL里两个单引号等于一个单引号
补充:
SQL中escape的用法
使用 ESCAPE 关键字定义转义符。 在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符。
例如,要搜索在任意位置包含字符串 5% 的字符串: WHERE ColumnA LIKE '%5/%%' ESCAPE '/'
前后两个%作为通配符使用,中间的%经过ESCAPE 转义,作为普通字符使用
欢迎注册吾爱缘分网,在这里可留言管理员需要找的资源哦。

0

主题

1

回帖

4

积分

新手上路

积分
4
发表于 2026-8-11 19:34:44 | 显示全部楼层
As a computer science student, I found this explanation of SQL escape characters really useful. Small details like escaping _, %, and single quotes can make a big difference when writing queries and debugging unexpected results. I’m currently learning SQL as part of my coursework, and examples like these make the concepts much easier to understand. Balancing programming assignments with other subjects can be challenging, especially when I also need to pay someone to do my English homework.
欢迎注册吾爱缘分网网站,别人有的咱都有哦。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|技术分享

GMT+8, 2026-9-20 23:52 , Processed in 0.073495 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表