Create a PL/SQL block to display all the department names from the Department table using cursors. The department names should be displayed in ascending order.
Column Name 1 - DEPARTMENT_ID NUMBER(5) PRIMARY KEY
Column Name 2 - DEPARTMENT_NAME VARCHAR(25) NOT NULL
Column Name 3 - LOCATION_ID VARCHAR(15)
Code
SET SERVEROUTPUT On;
declare
counter number;
v_dept department.department_name%type;
cursor c_dept is SELECT department_name FROM department;
BEGIN
dbms_output.put_line('Department Names are:');
OPEN c_dept;
LOOP
FETCH c_dept INTO v_dept;
EXIT WHEN c_dept%notfound;
dbms_output.put_line(v_dept);
END LOOP;
CLOSE c_dept;
END;
Sample Output:
Department Names are :
ADMIN
DEVELOPMENT
Note: Use '/' to terminate your query before compilation and evaluation
Error:
Failed Test
Test Case 2
Summary of tests
+------------------------------+
| 2 tests run / 1 test passed |
+------------------------------+