70 likes | 196 Vues
This document provides a comprehensive overview of arrays in PL/SQL, detailing their definition, types, and usage. Arrays enable the storage of multiple values of the same data type in an indexed manner. The guide includes syntax for declaring arrays, examples of populating elements, and iterating through them. By using PL/SQL’s built-in support, developers can efficiently manage collections of data. This resource is essential for programmers looking to enhance their skills in database management and effective data handling in Oracle PL/SQL.
E N D
ARRAY DikompilasiOleh : AryBimaKurniawan ST., MT.
Pendahuluan • Definisi • Tipe data bentukan yang dapat menyimpan sekumpulan nilai dari tipe data yang sama dan dikemas dalam bentuk larik. • Nilai dari elemen-elemen array dapat diacu atau diakses melalui indeksnya, perlu diperhatikan bahwa indeks array harus dari tipe data yang mempunyai keterurutan, seperti halnya tipe integer.
Membuat Tipe Array • Bentuk Umum : TYPE nama_tipe IS TABLE OF tipe_data INDEX BY BINARY_INTEGER; • Contoh : DECLARE TYPE array_ku IS TABLE OF CHAR(5) INDEX BY BINARY_INTEGER; X array_ku;
Mengisikan Nilai pada Elemen Array • Contoh 1 : BEGIN X(1) := ‘A’; X(2) := ‘B’; END; • Contoh 2 : BEGIN X(1) := 10; X(2) := 20; END;
Contoh 1 SET SERVEROUTPUT ON DECLARE TYPE LARIK IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; A LARIK; I INTEGER; BEGIN FOR I IN 1..5 LOOP A(I) := I * 10; END LOOP; FOR I IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(‘Nilai elemen larik ke-’ || TO_CHAR(I) || ‘ = ‘ || TO_CHAR(A(I))); END LOOP; END; /
Contoh 2 SET SERVEROUTPUT ON DECLARE TYPE SISWA IS TABLE OF VARCHAR2(25) INDEX BY BINARY_INTEGER; NAMA SISWA; I INTEGER; BEGIN NAMA(1) := ‘Arista Destriana’; NAMA(2) := ‘Yandri Gunawan’; NAMA(3) := ‘Herry Wahyudinata’; NAMA(4) := ‘Budi Raharjo’; NAMA(5) := ‘Noni Sutrisna’; FOR I IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(‘Nama siswa ke-’ || TO_CHAR(I) || ‘ : ‘ || NAMA(I)); END LOOP; END; /
Pustaka • Pemrograman PL/SQL ORACLE • Imam Heryanto dan Budi Raharjo • Penerbit Informatika Bandung • 2003