简体   繁体   English

PL/SQL 嵌套 IF 语句

[英]PL/SQL nested IF statements

I had so may errors after I ran the code.运行代码后,我遇到了很多错误。 The question ask to display the discount given for people who have balance > 100 and if that person has the insurance named BCBS, he/she will get 10% discount.该问题要求显示为余额 > 100 的人提供的折扣,如果该人拥有名为 BCBS 的保险,他/她将获得 10% 的折扣。 If he/she has insurance named SIH, he/she will get 20% discount.如果他/她有名为 SIH 的保险,他/她将获得 20% 的折扣。 And for people who has balance > 100 but not taking any of the two insurance mentioned before, he/she will get 5% discount.对于余额> 100但未参加上述两种保险的人,他/她将获得5%的折扣。 For those who have balance < 100, they need to pay the balance as it is.对于余额<100的人,他们需要按原样支付余额。 And the question also asked the patient to write his/her patient id.该问题还要求患者写下他/她的患者 ID。

accept ptid prompt 'Enter your patieint ID:'
begin
declare
pt_id number;
balance number;
pt_ins varchar2 (11);
amount number;

pt_id := &ptid;
select balance,pt_ins from billing;

if 
balance < 100;
begin
dbms_output.put_line('You need to pay RM '||balance);
end;

else
begin 

if pt_ins = 'BCBS'
begin 
amount := 0.9 * balance;
dbms_output.put_line('You need to pay RM '||amount);
end;

elsif pt_ins := 'SIH'
begin
amount := 0.8 * balance;
dbms_output.put_line('You need to pay RM '||amount);
end;

else
begin
amount := 0.95 * balance;
dbms_output.put_line('You need to pay RM '||amount);
end;

end;

end;

You have to use 'then': if (balance<100) then dbms_output... There should not be a semicolon after the condition You used to need parentheses around the condition.您必须使用 'then': if (balance<100) then dbms_output...条件后面不应该有分号 您过去需要在条件周围加上括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM