在oracle中执行存储过程后是否有自动提交?

Is there any auto commit happens after executing stored procedures in oracle?

我在 Oracle DB 中有 3 个表。我正在编写一个程序来根据某些条件删除所有 3 个表中的某些行。

我在程序中一一使用了所有三个删除语句。在执行提到的存储过程时,执行时是否发生了自动提交?

否则,我是否需要在最后手动编写提交代码?

存储过程范围内没有自动提交。但是,如果您使用的是 SQL Plus 或 SQL Developer,则可以根据设置自动提交。

您应该将提交和回滚作为存储过程代码的一部分来处理。

没有autocommit,但可以将提交命令设置到存储过程中。

示例 #1:no commit

create procedure my_proc as
begin
  insert into t1(col1) values(1);
end;

当你执行你需要调用的过程时 commit

begin
  my_proc;
  commit;
end;

示例 #2:commit

create procedure my_proc as
begin
  insert into t1(col1) values(1);
  commit;
end;

当您执行过程时,您不需要调用 commit 因为过程会这样做

begin
  my_proc;
end;

数据库级别没有自动提交,但您使用的 API 可能具有自动提交功能。 From Tom Kyte.

也就是说,我想补充:

除非你正在做一个自治事务,否则你应该避免直接在过程中提交:From Tom Kyte

摘录:

I wish PLSQL didn't support commit/rollback. I firmly believe transaction control MUST be done at the topmost, invoker level. That is the only way you can take these N stored procedures and tie them together in a transaction.

此外,还应该注意的是,对于 DDL(根据你的问题,这听起来不像你在你的过程中做任何 DDL,只是将其列为一个潜在的陷阱),Oracle 添加了一个隐式在 DDL 之前和之后提交。