Hello,
I am new to Oracle 11g and am currently enrolled in an Intro to Oracle class at my college. I have a question concerning a project that my professor has asked us to solve. I am looking for help/hints on how to write a PL/SQL anonymous block that will process records stored in the "emp" table. I have tried googling information on "varrays" and looking in the oracle documentation for PL/SQL Collections and Record, but to no prevail. I am hoping that I will be able to get some help from this community of professionals, that i am lacking from my online professor.
The program must perform the following tasks.
- Declare the required types and variables to store both the employee name and salary information (i.e., a counter variable may be needed also as an index).
- Use a loop to retrieve the first 10 "ename" and "sal" values for records in the "emp" table , store in two variable array of 10 elements (i.e., one array will store the name; the other array will store the salary)
- Use another loop to display the "ename" and "sal" information in the reverse order.
This is what my coding looks like, but will not produce anything but error messages:
--Just trying to get the ename part first--
SET SERVEROUTPUT ON
Declare
TYPE ename_array IS VARRAY(10) OF VARCHAR2(10);
v_names ename_array := ename_array();
BEGIN
FOR ename_array IN 1 .. 10 LOOP
SELECT ename INTO v_names FROM emp WHERE ROWNUM < 11;
END LOOP;
FOR ename_array IN REVERSE 1 .. 10 LOOP
dbms_output.put_line(v_names);
END LOOP;
END;
/
Thank you again for your time and patience with a eager to learn beginner like myself.