SQL*Plus 不会 运行 PL/SQL 阻塞

SQL*Plus does not run PL/SQL block

我在 SQL*Plus 中 运行 设置我的 PL/SQL 脚本时遇到问题。我可以正常地 运行 SQL 命令,但是当我想要 运行 任何 PL/SQL 代码时,它什么也没给出。请参阅下面的代码和输出。

DECLARE
    x_salary employee.salary%TYPE;
BEGIN
    select salary
    into x_salary
    from employee
    where ssn=&enter_ssn;

    --Output the result
    DBMS_OUTPUT.PUT_LINE('Salary is ' || x_salary);

EXCEPTION
    --Output when no records are returned
    WHEN no_data_found THEN
        DBMS_OUTPUT.PUT_LINE ('No employee found');

    WHEN others THEN
        DBMS_OUTPUT.PUT_LINE ('Error encountered, but cause unknown');
END;

PL/SQL程序需要/在sqlplus下定义程序后

DECLARE
 ...
BEGIN
 ...
END;

/

在您的脚本中 END; 之后的新行中添加一个斜杠 /

来自documentation

You must include a semicolon at the end of each SQL command and a slash (/) on a line by itself after each PL/SQL block in the file.

然后在SQL*Plus命令行中执行SQL文件为:

@C:\your_script.sql;