gpt4 book ai didi

oracle - SQL*Plus 脚本执行了两次

转载 作者:行者123 更新时间:2023-12-05 08:30:57 26 4
gpt4 key购买 nike

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

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

../sql/delete_societes.sql 是

DELETE FROM f2020.SOCIETES;
/

出于某种原因,它运行了两次,导致输出“0 lines deleted”被打印两次,并在我尝试执行插入而不是删除时导致错误。

最佳答案

让你的脚本做任何一个;

DELETE FROM f2020.SOCIETES
/

DELETE FROM f2020.SOCIETES;

没有斜杠。

From the documentation :

/(slash)

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

在下面的示例中:

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

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

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

与许多客户端一样,SQL*Plus 将 SQL 语句末尾的分号视为语句分隔符 - 它不是语句本身的一部分(这会导致一些混淆,例如动态 SQL 和 JDBC calls) - 当它看到它时它会执行命令。执行的语句保留在命令缓冲区中;如果您 list 查看当前命令缓冲区,它不会显示该分号。当您发出斜杠时,它会再次执行缓冲区。


PL/SQL 的情况略有不同; PL/SQL block 必须以分号结束, block 的一部分,并出现在缓冲区中。您必须对 execute a PL/SQL block 使用斜杠.

关于oracle - SQL*Plus 脚本执行了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60990822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com