Home > Back-end >  What does slash after trigger statement do in Oracle PL/SQL
What does slash after trigger statement do in Oracle PL/SQL

Time:09-29

There's a slash / after a trigger create statement as seen in this tutorial (Module 2: Creating Triggers). What does the / do here & why is it needed?

Example

create or replace trigger  DEPARTMENTS_BIU
    before insert or update on DEPARTMENTS
    for each row
begin
    if inserting and :new.deptno is null then
        :new.deptno := to_number(sys_guid(), 
          'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
    end if;
end;
/

CodePudding user response:

That's a PL/SQL block terminator.

In a GUI tool (such as SQL Developer or TOAD), you don't really need it (if you're executing statements or PL/SQL blocks alone), but - in a command-line tool (SQL Plus), you do need it, as otherwise nothing will be created - it (SQL Plus) will keep prompting next line(s) (as you hit the RETURN key), waiting for new statements or a terminator. For example:

SQL> create or replace trigger  DEPARTMENTS_BIU
  2      before insert or update on DEPARTMENTS
  3      for each row
  4  begin
  5      if inserting and :new.deptno is null then
  6          :new.deptno := to_number(sys_guid(),
  7            'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
  8      end if;
  9  end;
 10              --> these are lines
 11              --> I'm talking about
 12
 13
 14

Once you put slash here and press RETURN, then will that PL/SQL block be executed:

 14  /
    before insert or update on DEPARTMENTS
                               *
ERROR at line 2:
ORA-00942: table or view does not exist


SQL>

(I got an error as I don't have that table available, but we aren't discussing that).

  • Related