简体   繁体   English

如何回滚我的 Oracle PL/SQL 调试会话(SQL Developer)

[英]How do I ROLLBACK my Oracle PL/SQL debug session (SQL Developer)

When I debug my PL/SQL program using the debugger in Oracle SQL Developer, why is the work being done permanent?当我使用 Oracle SQL Developer 中的调试器调试我的 PL/SQL 程序时,为什么工作是永久完成的? I want the work to be ROLLBACK at the end.我希望工作在最后回滚。

The default behavior for an Oracle session when it finishes, in general, is do a COMMIT. Oracle 会话结束时的默认行为通常是执行 COMMIT。

When wondering about committing changes in your session when running PL/SQL, you also want to make sure your PL/SQL program itself is not:当想知道在运行 PL/SQL 时在会话中提交更改时,您还想确保您的 PL/SQL 程序本身不是:

  1. doing a COMMIT in the code在代码中执行 COMMIT
  2. running any DDL, such as creating or altering an object - this causes an implicit COMMIT运行任何 DDL,例如创建或更改对象 - 这会导致隐式 COMMIT

Now, as for debugging a PL/SQL program.现在,至于调试 PL/SQL 程序。

Do debug some PLSQL, we EXECUTE it.调试一些PLSQL,我们执行它。

When you start your debug session, you'll see the anonymous block of PL/SQL we use to kick off your program.当您开始调试会话时,您将看到我们用来启动您的程序的匿名 PL/SQL 块。

Scroll to the bottom -滚动到底部 -

在此处输入图片说明

Take that last line采取最后一行

--rollback

And remove the --并删除-

Now when our debug session runs, the very last thing that will happen before ending the session is the ROLLBACK.现在,当我们的调试会话运行时,在结束会话之前会发生的最后一件事是 ROLLBACK。

Now, let's DEMO a full scenario.现在,让我们演示一个完整的场景。 Here's some simple PLSQL - take in an EMPLOYEE_ID and update the EMPLOYEES table taking that employee's FIRST_NAME and making it UPPERCASE.这是一些简单的 PLSQL - 接收 EMPLOYEE_ID 并更新 EMPLOYEES 表,采用该员工的 FIRST_NAME 并将其设为大写。

create or replace procedure upper_EMP_NAME (
          EMP_ID_IN      in             number,
          EMP_NAME_OUT   out            varchar2
        ) as
         new_name varchar2(50);
        begin
          select upper(FIRST_NAME)
            into new_name
            from EMPLOYEES
           where EMPLOYEE_ID = EMP_ID_IN;

           update employees set first_name = new_name
           where EMPLOYEE_ID = EMP_ID_IN;

           emp_name_out := new_name;
        end upper_EMP_NAME;

Note: you may need to disable the TRIGGERs on this table for this to run.注意:您可能需要禁用此表上的触发器才能运行。

Now let's do the DEBUG.现在让我们进行调试。 We'll run this with EMPLOYEE_ID 101. We'll see what the local variable is set to, and the OUT parameter from running it.我们将使用 EMPLOYEE_ID 101 运行它。我们将看到局部变量设置为什么,以及运行它的 OUT 参数。 Then we'll see after it's done running, that EMPLOYEE 101 still has the original first name.然后我们会在它运行完成后看到,EMPLOYEE 101 仍然是原来的名字。

Animated GIF demo (sorry too big for SO) 动画 GIF 演示(抱歉太大了)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM