通常,在调用过程时,ASP.Net(我认为是.NET在做)会用单引号引起魔术。例如,以下将很好地工作...
dim aThing as string = "you're not as cool as your dog"
...
cmd.CommandText = "pkg_cool.s_you"
cmd.Parameters.Add(New OracleParameter("iSomeVar", OracleDbType.Varchar2)).Value = aThing
cmd.executeNonQuery()
该软件包有一个简单的更新查询
insert into someTable (colName)values(iSomeVar)
现在,如果我在ASP中做同样的事情,但是需要更改包以使用execute immediate
单引号,则需要转义;我是用asp做到的replace(aThing,"'","''")
。有人可以解释为什么吗?
-- the following will work fine if the asp variable "aThing" does not contain an apostrophe.
execute immediate
'insert into ' || vTableName || '(' || colName || ')values(''' || iSomeVar || ''')';
SQL Error: ORA-00917: missing comma
逃脱撇号的是RDBMS(关系数据库管理系统),而不是.NET。我猜想execute immediate
使用文字字符串,因为它是为组装动态SQL而设计的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句