游標

游標-處理多行數(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;

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • ORACLE自學教程 --create tabletestone ( id number, --序號usernam...
    落葉寂聊閱讀 1,243評論 0 0
  • cursor 游標:游標表示一個虛擬的結(jié)果集,相當于java中的引用(地址) 具體表示的是由selec...
    圣賢與無賴閱讀 525評論 0 1
  • 1、Check規(guī)則 Check (Agebetween15and30 )把年齡限制在15~30歲之間 2、新SQL...
    姜海濤閱讀 1,004評論 0 4
  • 在數(shù)據(jù)庫中,游標是一個十分重要的概念。游標提供了一種對從表中檢索出的數(shù)據(jù)進行操作的靈活手段,就本質(zhì)而言,游標實際上...
    碼謎媽咪閱讀 4,927評論 0 4
  • 我是誰,這真是一個復雜的哲學問題。畢竟這不是用“名字”可以回答得了的。 我們可能會以為,我之所以是我,都是我們自己...
    蘭草香舍2018閱讀 245評論 0 0

友情鏈接更多精彩內(nèi)容