oracle pl/sql ora-01722错误
我的程序中有一个简单的 oracle 语句:
update org.security_training_question a
set a.actv_indr = 'N' where a.qstn_id in (v_qstns_to_delete);
v_qstns_to_delete 是一个正在传递的参数。 它是一个 varchar2 字段,a.qstn_id 是一个数字字段。
调用存储过程时,对于 v_qstns_to_delete,我传递以下字符串:“24, 43, 23, 44, 21”。
当我运行语句输出存储过程时,它运行正常,但是当我将其作为存储过程运行时,我在上面的行中收到错误,提示“无效数字”。
有什么线索吗?
I have a simple oracle statement in my procedure:
update org.security_training_question a
set a.actv_indr = 'N' where a.qstn_id in (v_qstns_to_delete);
v_qstns_to_delete is a parameter being passed. It is a varchar2 field and a.qstn_id is a numeric field.
When calling the Stored Procedure, for v_qstns_to_delete I am passing the following String: "24, 43, 23, 44, 21".
When I run the statement output the stored procedure thenn it runs fine but when I run it as a stored procedure I get an error on the above line saying Invalid Number.
Any clue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能将“in”子句与这样的变量一起使用。 一种解决方法是
You can't use a "in" clause with a variable like that. One way around it is
如果
v_qstns_to_delete
是 varchar,您需要对其进行某种转换,以便让 Oracle 了解其中可能有多个项目。 一种方法是将字符串转换为项目表。假设
qstn_id
是一个 NUMBER 列,您可以:然后您可以将字符串从 SQL 转换为数字表:
要在列表中执行变量:
有关同一主题的更多信息,请参见 askTom。
if
v_qstns_to_delete
is a varchar, you would need to convert it somewhat to let Oracle understand that there may be several items in it. One method would be to convert the string to a table of items.Supposing
qstn_id
is a NUMBER column, you would:You could then convert a string to a table of number from SQL:
To do a variable in-list:
More on the same subject on askTom.