-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11. Nested Tables (Code Samples).html
More file actions
57 lines (57 loc) · 1.73 KB
/
11. Nested Tables (Code Samples).html
File metadata and controls
57 lines (57 loc) · 1.73 KB
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
56
57
<pre class="prettyprint linenums">--------------------------------------------------------------------------------------------------------------------
-------------------------------------------------NESTED TABLES------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
---------------The simple usage of nested tables
declare
type e_list is table of varchar2(50);
emps e_list;
begin
emps := e_list('Alex','Bruce','John');
for i in 1..emps.count() loop
dbms_output.put_line(emps(i));
end loop;
end;
---------------Adding a new value to a nested table after the initialization
declare
type e_list is table of varchar2(50);
emps e_list;
begin
emps := e_list('Alex','Bruce','John');
emps.extend;
emps(4) := 'Bob';
for i in 1..emps.count() loop
dbms_output.put_line(emps(i));
end loop;
end;
---------------Adding values from the tabledeclare
type e_list is table of employees.first_name%type;
emps e_list := e_list();
idx pls_integer := 1;
begin
for x in 100 .. 110 loop
emps.extend;
select first_name into emps(idx) from employees where employee_id = x;
idx := idx + 1;
end loop;
for i in 1..emps.count() loop
dbms_output.put_line(emps(i));
end loop;
end;
---------------delete example
declare
type e_list is table of employees.first_name%type;
emps e_list := e_list();
idx pls_integer := 1;
begin
for x in 100 .. 110 loop
emps.extend;
select first_name into emps(idx) from employees where employee_id = x;
idx := idx + 1;
end loop;
emps.delete(3);
for i in 1..emps.count() loop
if emps.exists(i) then
dbms_output.put_line(emps(i));
end if;
end loop;
end;</pre>