【发布时间】:2015-10-17 20:42:38
【问题描述】:
在下面的代码中,当本金金额的输入小于零或负数时,它应该引发异常并退出。但是下面会执行块中的所有语句,并在最后显示写入异常块中的错误消息。
一旦引发异常,我希望 Oracle 退出。请帮我解决这个问题。
declare
principle1 number;
rate1 number;
r1 number;
years1 number;
interest1 number;
principle2 number;
rate2 number;
r2 number;
years2 number;
interest2 number;
invalid_entry exception;
begin
principle1 := &principle1_amount1;
if (principle1 <= 0) then
raise invalid_entry;
end if;
rate1 := &rate_interest1;
r1 := rate1/100;
years1 := &years1;
interest1 := ComptInt_jk(principle1,r1,years1);
dbms_output.put_line('The interest for the principle amount ' || principle1
|| ' for ' || years1 || ' year/s at the rate of ' || rate1
||'% is '||interest1);
principle2 := &principle1_amount2;
rate2 := &rate_interest1;
r2 := rate2/100;
years2 := &years2;
interest2 := ComptInt_jk(principle2,r2,years2);
dbms_output.put_line('The interest for the principle amount ' || principle2
|| ' for ' || years2 || ' year/s at the rate of ' || rate2
||'% is '||interest2);
exception
when invalid_entry then
dbms_output.put_line('The data entered cannot be zero or negative ');
end;
/
【问题讨论】:
-
首先,我不明白这个问题。您发布的代码是做什么或不做什么,您想更改什么?您希望代码做什么?其次,您发布了两个问题,这两个问题的主题都以“#Oracle#PL/SQL:”开头。这不是其他人可能会搜索的术语,因此我不确定您为什么要这样做。我的偏见是解决这两个主题,但我想我会问,因为你显然是故意这样做的。
-
我也正要在标题中提到主题标签(?);这就是标签的用途。你是说你收到了所有的
dbms_output消息吗?或者只是提示您输入所有替换变量?如果是后者,那么与您之前的问题一样,您不了解该块是如何解析的,并且正试图让 PL/SQL 做一些它不适合做的事情。
标签: sql oracle exception plsql exception-handling