declare
a int:=9;
b int:=0;
begin
dbms_output.put_line('商是: '||a/b);
dbms_output.put_line('finished!!!');
exception
when zero_divide then
dbms_output.put_line('你做除法时,注意除数不能为0!!!');
dbms_output.put_line('sqlcode||sqlerrm');
end;
declare
v_bonus salary.奖金%type;
v_empid employee.员工编号%type:=20220107;
begin
select 奖金 into v_bonus from salary where 员工编号 = v_empid;
dbms_output.put_line('编号为'||v_empid||v_empid||'的奖金是:'||v_bonus);
exception
when no_data_found then
dbms_output.put_line('此员工编号: '||v_empid||'不存在');
dbms_output.put_line(sqlcode||sqlerrm);
when too_many_rows then
dbms_output.put_line('此员工有多个奖金,不能多给一个变量!');
dbms_output.put_line(sqlcode||sqlerrm);
when others then
dbms_output.put_line(sqlcode||sqlerrm);
end;
SQL> declare
2 v_bonus salary.奖金%type;
3 v_empid employee.员工编号%type:=20220107;
4 begin
5 select 奖金 into v_bonus from salary where 员工编号 = v_empid;
6 dbms_output.put_line('编号为'||v_empid||v_empid||'的奖金是:'||v_bonus);
7 exception
8 when no_data_found then
9 dbms_output.put_line('此员工编号: '||v_empid||'不存在');
10 dbms_output.put_line(sqlcode||sqlerrm);
11 when too_many_rows then
12 dbms_output.put_line('此员工有多个奖金,不能多给一个变量!');
13 dbms_output.put_line(sqlcode||sqlerrm);
14 when others then
15 dbms_output.put_line(sqlcode||sqlerrm);
16 end;
17 /
编号为2022010720220107的奖金是:20000
PL/SQL 过程已成功完成。