Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL*Plus script executed twice

I'm trying to run a script using sqlplus. My script is a simple delete statement. I execute it by putting the following in my ksh terminal:

sqlplus username/'password' @../sql/delete_societes.sql

../sql/delete_societes.sql is

DELETE FROM f2020.SOCIETES;
/

For some reason, it runs twice, causing the output "0 lines deteleted" to be printed twice and causing errors when I try to do an insert instead of a delete.

like image 570
Etsitpab Nioliv Avatar asked Feb 14 '26 16:02

Etsitpab Nioliv


1 Answers

Make your script do either;

DELETE FROM f2020.SOCIETES
/

or

DELETE FROM f2020.SOCIETES;

without the slash.

From the documentation:

/(slash)

Executes the most recently executed SQL command or PL/SQL block which is stored in the SQL buffer.

and in the example further down:

Enter a slash (/) to re-execute the command in the buffer

... which is exactly what you are seeing.

Elsewhere in those docs:

The semicolon (;) means that this is the end of the command. Press Return or click Execute. SQL*Plus processes the command and displays the results

Like many clients SQL*Plus treats the semicolon at the end of your SQL statement as a statement separator - it is not part of the statement itself (which causes some confusion for e.g. dynamic SQL and JDBC calls) - and when it sees it it executes the command. The executed statement stays in the command buffer; and if you list to see the current command buffer, it will not show that semicolon. When you issue a slash it executes the buffer again.


Things are slightly different for PL/SQL; there the PL/SQL block has to be terminated with a semicolon, which is part of the block, and appears in the buffer. You have to use a slash to execute a PL/SQL block.

like image 64
Alex Poole Avatar answered Feb 17 '26 14:02

Alex Poole