Oracle遊標的定義格式說明

來源:互聯網
上載者:User

遊標是從資料表中提取出來的資料,以暫存資料表的形式存放在記憶體中,在遊標中有一個資料指標,在初始狀態下指向的是首記錄,利用fetch語句可以移動該指標,從而對遊標中的資料進行各種操作,然後將操作結果寫回資料表中。如下例子注釋與說明:      set serveroutput on
     declare
         sh_no tssa.entry_sheet_td.sheet_no%type;        --該程式定義sh_no為與tssa.entry_sheet_td資料表中的sheet_no欄位類型相同的變數
         v_flow_inst tssa.entry_sheet_td.PROCESSINSTID%type;
         cursor mycursor is
             select sheet_no from entry_sheet_td a ,wfprocessinst b   where a.processinstid=b.processinstid and b.currentstate='7';
             cursorrecord mycursor%rowtype;        --mycursor為從entry_sheet_td資料表中提取的接入型障礙中流程結束而未歸檔工單資料構成的遊標,cursorrecord mycursor%rowtype定義記錄變數
     begin
         sh_no:='';
         open mycursor;        --開啟遊標,開啟遊標的過程有以下兩個步驟:1、將合格記錄送入記憶體,2、將指標指向第一條記錄。
         loop
              fetch mycursor into cursorrecord;             --要提取遊標中的資料,使用fetch命令,文法形式如:fetch 遊標名 into 變數名1, 變數名2,……;
              exit when mycursor%notfound;             --噹噹前迴圈的記錄值為空白時,即迴圈結束後,退出迴圈
              sh_no:=cursorrecord.sheet_no;
              dbms_output.put_line(sh_no);             --輸出當前滿足條件的工單號,此處可以進行一些邏輯處理         end loop;
         close mycursor;         --關閉遊標
     end;上面只是對遊標寫法的一個簡要說明。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.