需要帮助执行立即更新查询
我有这个查询,但它没有更新到数据库中。给定的“where”子句有效。当我独立运行查询时,它工作正常,但在此过程中它不起作用。没有任何异常或错误。你们能帮我找出问题出在哪里吗?
EXECUTE IMMEDIATE 'UPDATE ' || dest || ' SET COUNTRY_CODE = :v1 WHERE col_id = :v2'
USING l_vc_CountryCode, l_vc_ColId;
if SQL%ROWCOUNT > 1 THEN
inserts := inserts + 1;
counter := counter + 1;
IF counter > 500 THEN
counter := 0;
COMMIT;
END IF;
END IF;
我之前没有写提交代码。只是为了清楚起见。
I have this query and it's not updating into the database. The given "where" clause is valid. When I run the query independently, it works fine but in this Procedure it's not working. There is no exception or no error. Could you guys help me in figuring out where the problem is?
EXECUTE IMMEDIATE 'UPDATE ' || dest || ' SET COUNTRY_CODE = :v1 WHERE col_id = :v2'
USING l_vc_CountryCode, l_vc_ColId;
if SQL%ROWCOUNT > 1 THEN
inserts := inserts + 1;
counter := counter + 1;
IF counter > 500 THEN
counter := 0;
COMMIT;
END IF;
END IF;
I didn't write the commit code before. Just to clarity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为 col_id 是主键。因此,在 update 语句中
,您始终最多更新一行,因此条件
永远不会为真( 1 不 > 1 )
因此,如果您的过程中没有任何其他提交语句,您将永远不会提交这些更新。
顺便说一句:这样做的目的是什么,
为什么你不在工作结束时做出承诺呢?
I suppose that col_id is the primary key. So in the update statement
you are always updating at most one row and thus the condition
is never true ( 1 is not > 1 )
So if you don't have any other commit statement in your procedure, you will never commit those updates.
By the way: what is the purpose of this
why don't you just commit at the end of your work?
以下代码可以正常工作(即更新行)。
我怀疑你的错误在其他地方。
例如,如果您不初始化 COUNTER,则增量仍会将其保留为 null 并且永远不会提交。
或者,l_vc_ColId 可能是错误的数据类型并遭受无效转换。
The following code works okay (ie updates the row).
I suspect your error is elsewhere.
For example, if you don't initialise COUNTER, the increment will still leave it as null and it will never commit.
Or, l_vc_ColId may be the wrong datatype and suffering from an invalid conversion.
如果您使用动态 SQL 在数千次更新中更改“dest”表,您可能需要重新考虑您的设计。
更好地了解您的目标并使用绑定变量作为 where 条件。那么你可以使用 mod 或类似的方法提交每 x 行:
但对于你的例子,Marcin 是正确的,如果你一次只更新 1 行,那么
永远不会是真的;
编辑:
一个了解“目标”表的简单示例:
如果使用动态 SQL,则使用 Oracle 文档中的显式绑定变量(USING 子句)的简单示例:
有关更多阅读,请参阅 此处。
希望这有帮助,编码愉快
you may want to reconsider your design if your using dynamic sql to change the "dest" table in thousands of updates.
Much better to know your dest and use bind variables for the where conditions. then you can commit every x rows using mod or similar:
But for your example, Marcin is correct, if you are updating only 1 row at a time, then
will never be true;
EDIT:
A simple example knowing your "dest" table:
If using dynamic SQL, a simple example using explicit bind variables (USING clause) from Oracle docs:
For more reading, see here.
Hope this helps, happy coding
立即执行需要显式提交。我想你检查过了?
Execute immediate needs explicit commit. I guess you checked that ?