Example 1:
declare
name varchar2(10);
begin
select energy_name into name from opti_energy_tb where energy_name = '煤老';
dbms_output.put_line(name);
exception
when NO_DATA_FOUND then
dbms_output.put_line('无此数据');
end;
Example 2:
create or replace procedure add_ord(
v_ordid number,v_orddate Date,v_custid number,
v_shipdate date,v_total number)
IS
e_integrity exception;
e_shipdate exception;
pragma exception_init(e_integrity,-2291);
begin
if v_shipdate >= v_orddate then
insert into ord values(v_ordid,v_orddate,v_custid,v_shipdate,v_total);
else
raise e_shipdate;
end if;
exception
when dup_val_on_index then
raise_application_error(-20001,'该订单已存在');
when e_integrity then
raise_application_error(-20002,'该客户不存在');
when e_shipdate then
raise_application_error(-20003,'交付日期不能早于预定日期');
end;