日期:2014-05-17 浏览次数:21283 次
declare sum_balance int; cus_name varchar2 (20); err exception; begin cus_name:='&p_cus_name'; select sum(balance) into sum_balance from account, depositor where customer_name = cus_name and account.account_number = depositor.account_number; if sum_balance < 400 then dbms_output.put_line ('Bronze Customer'); elsif sum_balance < 700 then dbms_output.put_line ('Silver Customer'); else dbms_output.put_line ('Golden Customer'); end if; exception when no_data_found then dbms_output.put_line ('No such customer'); end;
DECLARE v_totnum INT; BEGIN SELECT Sum(1) INTO v_totnum FROM txdses41 WHERE 1=2; IF v_totnum<400 THEN Dbms_Output.put_line('Bronze Customer'); ELSIF v_totnum<700 THEN Dbms_Output.put_line('Silver Customer'); ELSE Dbms_Output.put_line('Golden Customer'); END IF; --EXCEPTION WHEN No_Data_Found THEN --Dbms_Output.put_line('No such customer'); END;
------解决方案--------------------
没数据的话,sum()会返回null,自然跑到最后一个else里面
------解决方案--------------------