PL/SQL Plus 脚本只给我数字

Sco*_*ott 3 oracle plsql sqlplus

我有一个 PL/SQL 脚本,我正在尝试使用 SQLPLUS 从命令外壳运行它。然而,每当我去运行它时,我得到的只是一个数字和一个等待输入的光标。当我按回车键时,它只会增加数字并重复该过程。这是一个做同样事情的虚拟查询

set serveroutput on

DECLARE
    cursor getServerTime IS
        SELECT sysdate as t  from dual;

    myTime getServerTime%ROWTYPE;
BEGIN
    open getServerTime;

    FETCH getServerTime into myTime;

    dbms_output.put_line(myTime.t);

    close getServerTime;
END;
Run Code Online (Sandbox Code Playgroud)

从我使用的命令外壳运行它: sqlplus me/myPass@myDB @"dummy.sql"

DCo*_*kie 6

您需要在 END 之后用另一行终止您的脚本;在第一列中包含“/”,因此:

set serveroutput on

DECLARE
    cursor getServerTime IS
        SELECT sysdate as t  from dual;
    myTime getServerTime%ROWTYPE;
BEGIN
    open getServerTime;
    FETCH getServerTime into myTime;
    dbms_output.put_line(myTime.t);
    close getServerTime;
END;
/
Run Code Online (Sandbox Code Playgroud)

当您通过 SQL Plus创建 PL/SQL 块时,“/”告诉 SQL Plus 运行自上次执行命令以来放入缓冲区的所有内容。您得到的递增数字是 SQL*Plus 为您提供脚本中的下一行编号 - 它正在等待您告诉它您已完成。