set serveroutput on;
标量:
declare v_name myTable.name%type;
begin
select name into v_ name frommyTablewhere id = &aaaaa;
dbms_output.put_line('名字:'||v_ name);
exception
when no_data_foundthen dbms_output.put_line('没有编号');
end;
复合:
declare type emp_record is record --定义记录类型
(
name emp.name%type,
salary emp.salary%type
);
myRecord emp_record;--定义记录变量
begin
select name,salary into myRecord from mytable where id =1;
exception
when no_data_found then dbms_output.put_line('没有编号');
end;
参照:
declare type my_cursor is ref cursor;
myCursor my_cursor;
v_name myTable.name% type;
begin
open myCursor for select name from myTable;
loop
fetch myCursor into name;
exit when myCursor% notfound;
end loop;
close myCursor;
exception
when no_data_found then dbms_output.put_line("没有编号");
end;