Skip to content

Commit ed46599

Browse files
Add files via upload
1 parent 552ad93 commit ed46599

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

varray_04.sql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* Creating Record Type at Database Level */
2+
CREATE TYPE emails AS OBJECT (
3+
email_id VARCHAR2(100),
4+
email_type VARCHAR2(100),
5+
primary_email CHAR(1)
6+
);
7+
/
8+
9+
--SELECT * FROM user_objects WHERE OBJECT_NAME='EMAILS' ;
10+
11+
/* Creating Varray */
12+
CREATE OR REPLACE TYPE emaillist AS
13+
VARRAY(5) OF emails;
14+
/
15+
16+
CREATE TABLE customers_emails (
17+
customer_id NUMBER,
18+
full_name VARCHAR2(100),
19+
email_ids emaillist
20+
);
21+
22+
DECLARE
23+
lv_email emaillist;
24+
lv_full_name customers_emails.full_name%TYPE;
25+
rec_emails emails;
26+
BEGIN
27+
DELETE FROM customers_emails;
28+
29+
INSERT INTO customers_emails VALUES (
30+
286,
31+
'Wilfred Welch',
32+
emaillist(emails('wilfred.welch1@internalmail', 'Home', 'N'), emails('wilfred.welch2@internalmail', 'Home', 'N'),
33+
emails('wilfred.welch3@internalmail', 'Office', 'Y'))
34+
);
35+
36+
INSERT INTO customers_emails VALUES (
37+
287,
38+
'Kristina Nunez',
39+
emaillist(emails('kristina1.nunez@internalmail', 'Home', 'N'), emails('kristina3.nunez@internalmail', 'Home', 'N'),
40+
emails('kristina2.nunez@internalmail', 'Office', 'Y'))
41+
);
42+
43+
COMMIT;
44+
SELECT
45+
email_ids
46+
INTO lv_email
47+
FROM
48+
customers_emails
49+
WHERE
50+
customer_id = 286;
51+
52+
SELECT
53+
emails(email_id, email_type, primary_email)
54+
INTO rec_emails
55+
FROM
56+
TABLE ( lv_email )
57+
WHERE
58+
primary_email = 'Y';
59+
60+
dbms_output.put_line(rec_emails.email_id
61+
|| ' - '
62+
|| rec_emails.email_type
63+
|| ' - '
64+
|| rec_emails.primary_email);
65+
66+
END;
67+
/

0 commit comments

Comments
 (0)