Encountered the symbol "/" while compiling package

Viewed 281

I'm trying something quite simple here, just creating a package and it's package body. This is my code(from oracle documentation):

create or replace PACKAGE emp_bonus_2 AS
   PROCEDURE calc_bonus (date_hired number);
END emp_bonus_2;
/
CREATE PACKAGE BODY emp_bonus_2 AS
   PROCEDURE calc_bonus
     (date_hired number) IS
   BEGIN
     DBMS_OUTPUT.PUT_LINE
       ('Employees hired on ' || date_hired || ' get bonus.');
   END;
END emp_bonus_2 ;
/

When compiling, I get this error:

Error(4,1): PLS-00103: Encountered the symbol "/"

I have used "/" before for creating triggers without any problem, so I don't know where the problem is. I tried removing the "/", which gave me a "Encountered CREATE" error.

I'm working on SQLDeveloper on an Oracle 11g database.

2 Answers

Your code:

create or replace PACKAGE emp_bonus_2 AS
   PROCEDURE calc_bonus (date_hired number);
END emp_bonus_2;
/
CREATE PACKAGE BODY emp_bonus_2 AS
   PROCEDURE calc_bonus
     (date_hired number) IS
   BEGIN
     DBMS_OUTPUT.PUT_LINE
       ('Employees hired on ' || date_hired || ' get bonus.');
   END;
END emp_bonus_2 ;
/

This code block is a script which creates two objects, a PACKAGE and a PACKAGE BODY.

The Code Editor in SQL Developer is designed for working with a single code object. You could copy and paste the first or second code objects, sans the '/', and you'd be fine.

If you want to execute the entire block, you can put it into a SQL Worksheet, and run with F5.

The '/' tells SQL Developer that you're done with your PL/SQL code. This has no meaning from the database's perspective, hence the error when you include that in the Code Editor - that's also being sent to the database.

When you execute that in a SQL Worksheet, SQL Developer sees the '/' and goes, ah, that's the end of that bit of code, go execute it, and then start again. The '/' never makes it to the database itself.

Note that in SQL Plus a '/' can also mean - 'go run that bit of code, again.' This can cause problems when building deployment scripts for SQL Plus, where you can have things executed more than once, because you've added a

Docs

The SQL Buffer The SQL buffer stores the most recently entered SQL command or PL/SQL block (but not SQL*Plus commands). The command or block remains in the buffer until replaced by the next SQL command or PL/SQL block. You can view the buffer contents with the LIST command.

You can execute the command or block in the SQL buffer using the RUN or /(slash) commands. RUN displays the command or block in the buffer before executing it. /(slash) executes the command or block in the buffer without displaying it first. For information about editing a command or block stored in the buffer see Editing Scripts in SQL*Plus Command-Line.

So it turns out it was my fault. As I was trying to compile the code from the package editor tab (Packages -> emp_bonus_2), it failed.
Moving all the code to a working sheet and executing it worked fine.

Related