oracle INDEX BY Pl/sql陣列

season0891發表於2011-02-21

--INDEX BY Pl/sql陣列
SET SERVEROUTPUT ON
DECLARE
       TYPE NumberTab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
       v_Numbers NumberTab;
BEGIN
     FOR v_Count in 1..10 LOOP
         v_Numbers(v_Count) := v_Count * 10;
     END LOOP;
    
     DBMS_OUTPUT.put_line('Table elements: ');
     FOR v_Count IN 1..10 LOOP
         DBMS_OUTPUT.put_line(' v_Numbers('|| v_Count||'): '||v_Numbers(v_Count));
     END LOOP;
    
  BEGIN
       DBMS_OUTPUT.put_line('v_Numbers(11): '|| v_Numbers(11));
  EXCEPTION
           WHEN NO_DATA_FOUND THEN
                DBMS_OUTPUT.put_line('No data found reading v_Numbers(11)!');
  END;
END;

--INDEX BY Pl/sql陣列002
SET SERVEROUTPUT ON
declare
       type T_customerTab is table of t_customer%rowtype index by binary_integer;
       t_customers T_customerTab;
begin
          select * into t_customers(1) from t_customer where rownum = 1;    
          DBMS_OUTPUT.put_line( 'customer_name: '||t_customers(1).customer_id || ' customer_name: '||t_customers(1).customer_name);
end;

COME FROM:http://www.blogjava.net/fine/archive/2007/03/12/103358.html

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

相關文章