在 Oracle 存储过程中,如何编写事务?我需要明确地做还是 Oracle 会自动锁定行?
最佳答案
您可能想浏览 concept guide ,特别是关于transactions的章节:
A transaction is a logical unit of work that comprises one or more SQL statements run by a single user. [...] A transaction begins with the user's first executable SQL statement. A transaction ends when it is explicitly committed or rolled back by that user.
您不必明确启动事务,它会自动完成。您必须通过提交(或回滚)指定事务的结束。
锁定机制是 DB 的基本部分,请参阅 Data Concurrency and Consistency 一章.
关于存储过程
存储过程是一组语句,它们在与调用 session (*) 相同的事务中执行。通常,事务控制(提交和回滚)属于调用应用程序。调用应用程序具有更广泛的流程视野(可能涉及多个存储过程),因此可以更好地确定数据是否处于一致状态。虽然您可以在存储过程中提交,但这不是常态。
(*) 除非该过程被声明为自治事务,在这种情况下,该过程作为独立 session 执行(感谢 be here now ,现在我明白你的意思了)。
关于sql - Oracle 存储过程中的事务如何工作?是否存在隐式交易?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3853827/