InterviewSolution
Saved Bookmarks
| 1. |
How can we create Nested Tables in PL/SQL? |
|
Answer» Nested tables are one of the collection types in PL/SQL. They are created EITHER in PL/SQL block or at schema level. These are LIKE a 1D array, but its size can GET increased dynamically. The following is the syntax: TYPE type_name IS TABLE OF element_type [NOT NULL]; name_of_table type_name;The following is an example: DECLARE TYPE deptname IS TABLE OF VARCHAR2(10); TYPE budget IS TABLE OF INTEGER; names deptname; deptbudget budget; BEGIN names := deptname ('Finance', 'Sales', 'MARKETING'); deptbudget := budget (89899, 67879, 98999); FOR i IN 1 .. names.count LOOP dbms_output.put_line('Department = '||names(i)||', Budget = ' || deptbudget(i)); end loop; END; /The output: Department = Finance, Budget = 89899 Department = Sales, Budget = 67879 Department = Marketing, Budget = 98999 |
|