參考網站
http://abu.tw/2010/04/plsql-table-oracle-array-like.html
DECLARE -- 宣告 RECORD, TYPE 及變數 TYPE R_HANDSET IS RECORD( BRAND VARCHAR2(10), MODEL_NAME VARCHAR2(20), PRICE NUMBER); TYPE T_HANDSET IS TABLE OF R_HANDSET INDEX BY PLS_INTEGER; HANDSETS T_HANDSET; BEGIN -- 塞值進 RECORD ARRAY HANDSETS(1).BRAND := 'HTC'; HANDSETS(1).MODEL_NAME := 'TATTOO'; HANDSETS(1).PRICE := 6000; HANDSETS(2).BRAND := 'APPLE'; HANDSETS(2).MODEL_NAME := 'IPHONE'; HANDSETS(2).PRICE := 27000; HANDSETS(3).BRAND := 'NOKIA'; HANDSETS(3).MODEL_NAME := 'N82'; HANDSETS(3).PRICE := 15000; FOR I IN 1 .. HANDSETS.COUNT LOOP DBMS_OUTPUT.PUT_LINE('第 ' || TO_CHAR(I) || ' 筆 - '); DBMS_OUTPUT.PUT_LINE('廠牌 : ' || HANDSETS(I).BRAND); DBMS_OUTPUT.PUT_LINE('名稱 : ' || HANDSETS(I).MODEL_NAME); DBMS_OUTPUT.PUT_LINE('價格 : ' || TO_CHAR(HANDSETS(I).PRICE)); DBMS_OUTPUT.PUT_LINE(' '); END LOOP; END;
沒有留言:
張貼留言