Assignment 1:
一、
Create table employee (
empNo number,empName varchar2(20),empSalary number(8,2),grade char(1));
二、
CREATE OR REPLACE PROCEDURE sp_Get_Grade
(
p_eNo IN EMPLOYEE.EmpNo%TYPE:=0 ,
p_eGrade OUT EMPLOYEE.Grade%TYPE
)
ISBEGINSELECT grade into p_eGrade FROM employee WHERE EmpNo = p_eNo;EXCEPTIONWHEN NO_DATA_FOUND THENp_eGrade := 'Z';WHEN OTHERS THENp_eGrade :='Z';dbms_output.put_line('*** Error occurred ***');dbms_output.put_line('SQLCODE: '||to_char(SQLCODE));dbms_output.put_line('SQLERRM: '||SQLERRM);END;/
三、
DECLAREv_employeeNo EMPLOYEE.EmpNo%TYPE;v_employeeGrade EMPLOYEE.Grade%TYPE;BEGINv_employeeNo := 1;sp_Get_Grade(v_employeeNo, v_employeeGrade);IF v_employeeGrade = 'Z' THENdbms_output.put_line('Employee No Not Found');ELSEdbms_output.put_line('Employee Grade is '||v_employeeGrade);END IF;EXCEPTIONWHEN OTHERS THENdbms_output.put_line('*** Error occurred ***');
dbms_output.put_line('SQLCODE: '||to_char(SQLCODE));dbms_output.put_line('SQLERRM: '||SQLERRM);END;/