Oracle遊標型別作為傳入傳出引數

tianyazlf發表於2012-06-29
--遊標型別傳入引數 
DECLARE 
  /*CURSOR cur_ttt IS
  SELECT 1 a FROM dual;*/
 
  TYPE typ_cur IS REF CURSOR; 
  val_cur typ_cur;
 
  PROCEDURE temp_sp1(x_cur OUT typ_cur) IS
  BEGIN
      OPEN x_cur FOR SELECT 1 a FROM dual UNION ALL SELECT 2 FROM dual;
  END;
 
  PROCEDURE temp_sp2(p_cur IN typ_cur) IS
    i NUMBER;
  BEGIN
    LOOP
      FETCH p_cur INTO i;
      EXIT WHEN p_cur%NOTFOUND;
      dbms_output.put_line(i);
    END LOOP;
    CLOSE p_cur;
  END;
BEGIN
  temp_sp1(val_cur);
  temp_sp2(val_cur);
 
  OPEN val_cur FOR SELECT 3 a FROM dual UNION ALL SELECT 4 FROM dual;
  temp_sp2(val_cur);
END;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25128871/viewspace-734191/,如需轉載,請註明出處,否則將追究法律責任。

相關文章