Display department names using Cursors.Create a PL/SQL block to display all the department names from the Department table using cursors

TABLE:

Column name Data type Constraints

DEPARTMENT_ID NUMBER(5) PK
DEPARTMENT_NAME VARCHAR2(25) NOT NULL
LOCATION_ID VARCHAR2(15)

I have tried this. But still i didn’t get my output. Can somebody help me to get the output.

set serveroutput on;
DECLARE
DEPARTMENT_NAME VARCHAR2(25);
CURSOR dep_cursor IS
SELECT
DEPARTMENT_NAME
FROM
department;
BEGIN
OPEN dep_cursor;
FETCH dep_cursor INTO DEPARTMENT_NAME;
DBMS_OUTPUT.PUT_LINE(‘Department Names are :’ || DEPARTMENT_NAME);
CLOSE dep_cursor;
END;
/

Error message: Bind variable “~” not declared.

Sample output:

Department Names are :
ADMIN
DEVELOPMENT
TESTING

where is the variable name ??
it should be
DBMS_OUTPUT.PUT_LINE(‘Department Names are :’ || DEPARTMENT_NAME);
Also set serveroutput on ; from console

1 Like

Sir I have tried this but i didn’t get the output.