Oracle集合的first, last , next ,count,exist

abstractcyj發表於2013-10-31
DECLARE
  TYPE typ_nums IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
  v_nums  typ_nums;
  v_index NUMBER;
BEGIN
  v_nums(1) := 12;
  v_nums(3) := 45;
  v_nums(56) := 67;

  dbms_output.put_line('v_nums.first = ' || v_nums.first);
  dbms_output.put_line('v_nums.last = ' || v_nums.last);
  dbms_output.put_line('v_nums.count = ' || v_nums.count);

  IF v_nums.exists(6) THEN
    dbms_output.put_line(' 6 exist');
  ELSE
    dbms_output.put_line(' 6 not exist');
  END IF;

  IF v_nums.exists(56) THEN
    dbms_output.put_line('56 exist');
  ELSE
    dbms_output.put_line('56 not exist');
  END IF;

  v_index := v_nums.first;
  WHILE v_index IS NOT NULL LOOP
    dbms_output.put_line('v_nums(' || v_index || ') = ' || v_nums(v_index));
    v_index := v_nums.next(v_index);
  END LOOP;
END;

指令碼輸出是:

v_nums.first = 1
v_nums.last = 56
v_nums.count = 3
 6 not exist
56 exist
v_nums(1) = 12
v_nums(3) = 45
v_nums(56) = 67

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

相關文章