1. 程式人生 > >遊標的定義、顯示遊標、隱式遊標語法

遊標的定義、顯示遊標、隱式遊標語法

 遊標的定義: 1.顯示遊標  普通顯示遊標 帶引數:    CURSOR c(pi_month varchar2,file_type varchar2) IS      SELECT item_id,item_title     FROM item      where month_id = pi_month; 不帶引數:     CURSOR c IS      SELECT item_id,item_title     FROM item; 2.隱式遊標 2.1 select into 隱式遊標 select tname into l_tname from tab where rownum
= 1 ;
2.2 for .. in 隱式遊標 begin
for c in (select tname from tab) loop
dbms_output
.put_line(c.tname);
end loop;
end;
遊標使用語法: open c ; loop     fetch c into l_tname ;     exit when c%notfound ;     dbms_output.put_line(l_tname); end loop; close c; 遊標的資料取法: 優點不需要去逐個定義遊標內的資料的各個欄位   CURSOR TEST IS
     SELECT item_id,item_title     FROM item; V_CURSOR TEST%ROWTYPE; open TEST; loop     fetch TEST into V_CURSOR ;     exit when c%notfound;     dbms_output.put_line(V_CURSOR.ITEM_ID);     dbms_output.put_line(V_CURSOR.ITEM_TITLE); end loop; close TEST;