开发者

Quoting identifiers for dynamic SQL in PL/SQL

Is there a PL/SQL function or general technique to quote unqualified identifiers (e.g., mytable) for use in a dynamically constructed SQL query? How about partially or fully qualified identifiers (a.b@c)?

Consider this contrived example:

CREATE PROCEDURE by_the_numbers(COL_NAME VARCHAR, INTVAL INTEGER) IS
  ...
BEGIN
  -- COL_NAME is interpolated into SQL string
  -- INTVAL gets bound to :1
  st开发者_StackOverflow社区mt := 'SELECT * FROM tbl WHERE ' || COL_NAME || ' = :1';
  ...
END

... where we don't want to permit naive SQL injection in COL_NAME (e.g., a value of '1=1 or 1').


There is dbms_assert: http://www.oracle-base.com/articles/10g/dbms_assert_10gR2.php for preventing sql injection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜