I need to write a program to print a record from HR.EMPLOYEES but I keep getting
ID: 3663455 • Letter: I
Question
I need to write a program to print a record from HR.EMPLOYEES but I keep getting an error- not sure how to do this. Set echo on Set up a spool file to receive your output for submission. I would suggest c:aspool.txt . DECLARE variables for Department_ID, Employee_ID, First_Name, Last_Name, and Salary In the BEGIN block add a select statement to read a record into the declared variables from HR.EMPLOYEES for an Employee_ID to be determined at run time Add DBMS_OUTPUT lines to print each variable for the select record Add a EXCEPTION block to report when no data is found Compile and run the procedure for the Employee, 114 Close the spool file
Explanation / Answer
The subsequent query in pl/sql will be:
Declare
Department_ID HR.EMPLOYEES.department_id%type;
Employee_ID HR.EMPLOYEES.employee_id%type;
First_Name HR.EMPLOYEES.first_name%type;
Last_Name HR.EMPLOYEES.last_name%type;
Salary HR.EMPLOYEES.salary%type;
BEGIN
select Department_ID, Employee_ID, First_Name, Last_Name, Salary into Department_ID, Employee_ID, First_Name, Last_Name, Salary from HR.EMPLOYEES where employee_id=employee_ID;
dbms_output.put_line('Department_ID' || Department_ID);
dbms_output.put_line('Employee_ID' || Employee_ID);
dbms_output.put_line('First_Name' || First_Name);
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No such customer!');
WHEN others THEN
dbms_output.put_line('Error!');
END;