Oracle 当有换行符时,为什么我的PL/SQL过程不编译?

Oracle 当有换行符时,为什么我的PL/SQL过程不编译?,oracle,plsql,toad,Oracle,Plsql,Toad,下面是我试图编译的存储过程中的一些逻辑。当没有换行符时,它编译得很好。但是,当我分解它时,它不会编译。为什么呢 正确工作时的代码: DECLARE curr_fy varchar2(4); last_fy varchar2(4); get_month number; BEGIN get_month := to_number(to_char(sysdate, 'MM')); If get_month < 6 then curr_fy := to_char(sysdate, 'YYYY');

下面是我试图编译的存储过程中的一些逻辑。当没有换行符时,它编译得很好。但是,当我分解它时,它不会编译。为什么呢

正确工作时的代码:

DECLARE
curr_fy varchar2(4);
last_fy varchar2(4);
get_month number;
BEGIN
get_month := to_number(to_char(sysdate, 'MM'));
If get_month < 6 then
curr_fy := to_char(sysdate, 'YYYY');
last_fy := to_char(sysdate, 'YYYY') - 1;
END IF;
If get_month > 5 then
curr_fy := to_char(sysdate, 'YYYY') + 1;
last_fy := to_char(sysdate, 'YYYY');
END IF;
dbms_output.put_line(curr_fy);
END;
声明
curr_fy varchar2(4);
最后一次varchar2(4);
获取月号;
开始
get_month:=to_number(to_char(sysdate,'MM'));
如果获得的月数小于6,则
curr_fy:=to_char(sysdate,'YYYY');
last_fy:=to_char(sysdate,'YYYY')-1;
如果结束;
如果获得月数>5,则
curr_fy:=to_char(sysdate,'YYYY')+1;
last_fy:=to_char(sysdate,'YYYY');
如果结束;
dbms_输出。输出线(curr_fy);
结束;
当代码无法正常工作时,请执行以下操作:

DECLARE

curr_fy varchar2(4);
last_fy varchar2(4);
get_month number;

BEGIN

get_month := to_number(to_char(sysdate, 'MM'));

If get_month < 6 then
curr_fy := to_char(sysdate, 'YYYY');
last_fy := to_char(sysdate, 'YYYY') - 1;
END IF;

If get_month > 5 then
curr_fy := to_char(sysdate, 'YYYY') + 1;
last_fy := to_char(sysdate, 'YYYY');
END IF;

dbms_output.put_line(curr_fy);

END;
声明
curr_fy varchar2(4);
最后一次varchar2(4);
获取月号;
开始
get_month:=to_number(to_char(sysdate,'MM'));
如果获得的月数小于6,则
curr_fy:=to_char(sysdate,'YYYY');
last_fy:=to_char(sysdate,'YYYY')-1;
如果结束;
如果获得月数>5,则
curr_fy:=to_char(sysdate,'YYYY')+1;
last_fy:=to_char(sysdate,'YYYY');
如果结束;
dbms_输出。输出线(curr_fy);
结束;
在编译代码的第二个版本时,我收到以下错误消息:ORA-00900:无效SQL语句


我使用的是最新版本的TOAD。

我没有使用TOAD,但我猜TOAD将每一行后跟一个空行视为单独的SQL语句。因此,在您的例子中,TOAD可能试图将
声明为不正确的SQL语句


我的建议是使用鼠标光标选择/突出显示整个匿名块,然后单击执行按钮。这通常适用于SQL Developer之类的免费工具。

我想这与Toad有关,因为您的两个示例都是在SQL Developer中编译的。在PL/SQL Developer中编译并运行良好。请编辑您的问题,并包含有关在Toad中运行此程序时出现的错误的信息。谢谢。也许蟾蜍的行为类似于SQL*Plus:一个空行终止语句。您应该使用F9执行,而不是CTRL+Enter或Shift+F9。后两种方法使用传统代码将空行解释为SQL终止符,这在技术上是不正确的。F9使用一个解析器来准确地检测语句。有很多理由说明为什么F9应该使用在蟾蜍论坛上详细介绍的遗留功能之上。