Question
In this question, the codes are provided as below. You are not required to write the code, rather, you are required to run the code
In this question, the codes are provided as below. You are not required to write the code, rather, you are required to run the code and understand what happened to the program, and answer the following questions.
1/ After copying the code and running it, do you think that the program has inserted a new record to the departments table ? Briefly write down the reasons that help you to get that conclusion.
2/ After reading the error message in the output, which part of the codes caused this error?
3/ Please change the provided codes, make the program run without error. Write down the changed part only (no more one line).
CODE:
DECLARE
error_code number;
error_message varchar2 (255);
dept_id departments.department_id%TYPE := 777;
dept_name departments.department_name%TYPE := 'Deleteme';
dept_mgr_id departments.manager_id%TYPE ;
dept_loc_id departments.location_id%TYPE := 1700;
BEGIN
INSERT INTO departments
VALUES (dept_id, dept_name, dept_mgr_id, dept_loc_id);
DBMS_OUTPUT.PUT_LINE ( 'A new department is created. ' || CHR (10) ||
'Its ID is ' || dept_id || ', its name is ' || dept_name ||', ' ||
'its manager id is '|| NVL (dept_mgr_id, 'Not assigned') ||
', its location ID is ' || dept_loc_id ||'.');
Exception
WHEN OTHERS THEN
error_code := SQLCODE;
error_message := SQLERRM;
DBMS_OUTPUT.PUT_LINE (CHR (10) ||'Print from error handler, '||
CHR(10)|| 'The error code is :' || error_code || '.'||
CHR(10)|| 'The mesg is ; ' || error_message || '.' );
END;
/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started