次の1次元のARRAYデータ型およびテーブルについて考えてみましょう。
CREATE TYPE phonenumbers AS VARRAY(20) OF CHAR(10); CREATE TABLE employee_info (eno INTEGER, phonelist phonenumbers);
テーブルには次の値が取り込まれます。
/* The first 2 elements are populated; the rest are uninitialized. */ INSERT INTO employee_info VALUES (1, phonenumbers('1112223333', '6195551234')); /* Empty ARRAY instance */ INSERT INTO employee_info VALUES (2, phonenumbers()); /* Update the empty ARRAY instance such that element 3 is set to a value; then elements 1 and 2 are set to NULL, the rest are uninitialized. */ UPDATE employee_info SET phonelist[3] = '8584850000' WHERE id = 2;
次の問合わせは、NULLまたは非NULL値を含むphonelist配列内の要素の数を返します。
SELECT eno, phonelist.OCOUNT() FROM employee_info;
問合わせの結果を次に示します。
ENO phonelist.OCOUNT() --- ------------------ 1 2 (the first 2 elements have values that are non-NULL) 2 3 (the first 3 elements have NULL or values that are non-NULL)