简体   繁体   English

在DB2中等效于MS-SQL QUOTENAME

[英]What is the equivalent of MS-SQL `QUOTENAME` in `DB2`

I change from MS-SQL to DB2. 我从MS-SQL更改为DB2。 In the procedures are some QUOTENAME methods to prevent sql-injection. 该过程中有一些QUOTENAME方法可防止sql注入。 Does in DB2 exist a function like this? 在DB2中是否存在这样的功能?

I'm afraid you misunderstand the purpose of QUOTENAME -- it's not to "prevent SQL injection"; 恐怕您误解了QUOTENAME的目的-不是为了“防止SQL注入”; it is " to make the input string a valid SQL Server delimited identifier ." 这是“ 使输入字符串成为有效的SQL Server分隔标识符”

Since the only way to quote an identifier in Db2 (and, I believe, in standard SQL) is to enclose it in double quotation marks, you can easily achieve the same functionality by using a REPLACE function: 由于在Db2中引用标识符的唯一方法(并且,我相信在标准SQL中)是用双引号将其引起来,因此可以通过使用REPLACE函数轻松实现相同的功能:

create function quotename (input varchar (128)) returns varchar(128)
return '"' || replace(input, '"', '""') || '"'   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM