在SQL中转义特殊字符

在SQL中转义特殊字符

本文介绍了在SQL中转义特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Oracle中是否有一种简便的方法来转义SQL语句中的特殊字符? (即%,& ;、')关于人工转义字符,我看到了这个链接,但是我认为Oracle可能提供了一个更简单的方法.

Is there an easy way in Oracle to escape special characters in a SQL statement? (i.e. %, &, ') I saw this link in regard to manually escaping characters, but I thought Oracle may have provided an easier way to do so.

注意:我正在通过ORM生成动态SQL select语句.

Note: I'm generating dynamic SQL select statements through an ORM.

推荐答案

如果使用绑定变量和ORM,则应自动处理嵌入的单引号和&符;这些是SQL * Plus或SQL * Developer中的特殊字符.

If using bind variables and ORM, embedded single quotes and ampersands should be handed automatically; those are special characters in SQL*Plus or SQL*Developer.

要使用LIKE查找文字字符%和_(而不是其多字符和单字符通配符版本),请使用like条件的escape子句:

To use LIKE where looking for the literal characters % and _ (not their multi- and single-character wildcard versions), you'd use the escape clause of the like condition:

select * from my_table where some_text like '/%%' escape '/';

将仅返回some_text以百分号开头的行.

will only return the rows where some_text begins with a percent sign.

这篇关于在SQL中转义特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:45