ORACLE intialize collection
SET SERVEROUTPUT ON
DECLARE
TYPE t_rec IS RECORD (
id NUMBER,
val1 VARCHAR2(10),
val2 VARCHAR2(10),
val3 VARCHAR2(10),
val4 VARCHAR2(10),
val5 VARCHAR2(10),
val6 VARCHAR2(10),
val7 VARCHAR2(10),
val8 VARCHAR2(10),
val9 VARCHAR2(10)
);
l_rec t_rec;
BEGIN
-- Pre-18c - Direct assignment to record columns.
l_rec.id := 1;
l_rec.val1 := 'ONE';
l_rec.val9 := 'NINE';
DBMS_OUTPUT.put_line('(1) Record1 val1 = ' || l_rec.val1 || ' val9 = ' || l_rec.val9);
l_rec.id := 2;
l_rec.val2 := 'TWO';
l_rec.val8 := 'EIGHT';
DBMS_OUTPUT.put_line('(1) Record2 val1 = ' || l_rec.val1 || ' val9 = ' || l_rec.val9);
-- 18c - Qualified expression using position notation.
l_rec := t_rec(1, 'ONE', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'NINE');
DBMS_OUTPUT.put_line('(2) Record1 val1 = ' || l_rec.val1 || ' val9 = ' || l_rec.val9);
l_rec := t_rec(1, NULL, 'TWO', NULL, NULL, NULL, NULL, NULL, 'EIGHT', NULL);
DBMS_OUTPUT.put_line('(2) Record2 val1 = ' || l_rec.val1 || ' val9 = ' || l_rec.val9);
-- 18c - Qualified expression using named association.
l_rec := t_rec(id => 1, val1 => 'ONE', val9 => 'NINE');
DBMS_OUTPUT.put_line('(3) Record1 val1 = ' || l_rec.val1 || ' val9 = ' || l_rec.val9);
l_rec := t_rec(id => 1, val2 => 'TWO', val8 => 'EIGHT');
DBMS_OUTPUT.put_line('(3) Record2 val1 = ' || l_rec.val1 || ' val9 = ' || l_rec.val9);
END;
/
(1) Record1 val1 = ONE val9 = NINE
(1) Record2 val1 = ONE val9 = NINE
(2) Record1 val1 = ONE val9 = NINE
(2) Record2 val1 = val9 =
(3) Record1 val1 = ONE val9 = NINE
(3) Record2 val1 = val9 =
PL/SQL procedure successfully completed.
SQL>