Plus脚本执行两次

Plus脚本执行两次

本文介绍了SQL * Plus脚本执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用sqlplus运行脚本.我的脚本是一个简单的delete语句.我通过将以下内容放入我的ksh终端来执行它:

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是

../sql/delete_societes.sql is

DELETE FROM f2020.SOCIETES;
/

由于某种原因,它运行两次,导致输出已删除0行"的输出被打印两次,并且在我尝试执行插入操作而不是删除操作时导致错误.

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.

推荐答案

使您的脚本也可以执行;

Make your script do either;

DELETE FROM f2020.SOCIETES
/

DELETE FROM f2020.SOCIETES;

不带斜杠.

从文档中:

执行存储在SQL缓冲区中的最近执行的SQL命令或PL/SQL块.

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

,在示例中更进一步:

...这正是您所看到的.

... which is exactly what you are seeing.

这些文档中的其他地方:

就像许多客户端一样,SQL * Plus会将分号放在SQL语句的末尾作为语句分隔符-它不是语句本身的一部分(这会引起动态SQL和JDBC等混淆)调用)-并在其看到时执行命令.已执行的语句保留在命令缓冲区中;如果您list查看当前的命令缓冲区,它将不会显示该分号.发出斜线时,它将再次执行缓冲区.

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.

PL/SQL的情况略有不同; PL/SQL块必须以分号结尾,分号是该块的一部分,并出现在缓冲区中.您必须使用斜杠执行PL/SQL块.

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.

这篇关于SQL * Plus脚本执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 18:01