游標-處理多行數(shù)據(jù)類型
--方法一
declare
? ? --定義游標
? ? cursor user_sum_cursor is select sum,name,time from user where id = 1;
begin
? ? for i in user_sum_cursor? loop
? ? ? ? dbms_output.put_line(i.sum || ',' || i.name || ',' || i.time);
? ? end loop;
end;
--方法二
declare
? ? --定義記錄類型
? ? type user_record is record(
? ? ? ? ? ? v_sum user.sum%type,
? ? ? ? ? ? v_id user.id%type,
? ? ? ? ? ? v_email user.email%type
? ? );
? ? --聲明記錄類型的成員變量
? ? v_user_record user_record;
? ? --定義游標
? ? cursor user_sum_cursor is select sum,id,email from user where id=1;
begin
? ? --打開游標
? ? open?user_sum_cursor;
? ? --提取游標
? ? fetch?user_sum_cursor into v_user_record;
? ? --循環(huán)判斷游標是否有值,%found為空值
? ? while?user_sum_cursor%found loop
? ? ? ? dbms_output.put_line(v_user_record.v_sum || ',' || v_user_record.id || ',' || v_user_record.email);
? ? ? ? fetch user_sum_cursor into v_user_record;
? ? end loop;
? ? --關閉游標
? ?close?user_sum_cursor;
end;