-
Notifications
You must be signed in to change notification settings - Fork 0
/
varray_03.sql
55 lines (45 loc) · 1.27 KB
/
varray_03.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
SET SERVEROUTPUT ON;
/* Creating a array for storing 5 emails of each VARCHAR2(100) */
CREATE OR REPLACE TYPE emaillist AS
VARRAY(5) OF VARCHAR2(100);
/
/* Creating a database table having column that store varray. Each varray is VARCHAR2(100) */
CREATE TABLE customers_emails (
customer_id NUMBER,
full_name VARCHAR2(100 BYTE),
emails emaillist
);
DECLARE
lv_email emaillist;
lv_full_name customers_emails.full_name%TYPE;
BEGIN
DELETE FROM customers_emails;
INSERT INTO customers_emails VALUES (
286,
'Wilfred Welch',
emaillist('wilfred.welch1@internalmail', 'wilfred.welch2@internalmail')
);
INSERT INTO customers_emails VALUES (
287,
'Wilfred Welch',
emaillist('kristina.nunez2@internalmail', 'kristina.nunez2@internalmail')
);
COMMIT;
/* Retrieving vaaray values */
SELECT
full_name,
emails
INTO
lv_full_name,
lv_email
FROM
customers_emails
WHERE
customer_id = 286;
FOR i IN 1..lv_email.count LOOP
dbms_output.put_line(lv_full_name
|| ' - '
|| lv_email(i));
END LOOP;
END;
/