oracle转义功能

前端之家收集整理的这篇文章主要介绍了oracle转义功能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在oracle中是否有任何函数SQL查询中转义错误的字符?我有从不同的字符串构建查询代码,其中一些可能包含’字符,这打破了SQL查询.

解决方法

正如Yahia指出的那样,你应该总是使用绑定变量而不是动态地动态组装sql语句.这是保护自己免受sql注入攻击的正确方法.转义字符串可提供更低级别的保护.

话虽这么说,假设您使用的是Oracle 10.1或更高版本,您可以使用q引用语法.就像是

1  select q'[This is a string with an embedded ']' str
  2*   from dual
sql> /

STR
-----------------------------------
This is a string with an embedded '

您可以使用许多其他字符替换[和]字符,具体取决于字符串中可能出现的字符

1  select q'<This is a string with an embedded '>' str
  2*   from dual
sql> /

STR
-----------------------------------
This is a string with an embedded '

sql> ed
Wrote file afiedt.buf

  1  select q'{This is a string with an embedded '}' str
  2*   from dual
sql> /

STR
-----------------------------------
This is a string with an embedded '

猜你在找的Oracle相关文章