CREATE EXCEPTION CEO 'Can’t Assign CEO to Project.'; SET TERM !!; CREATE PROCEDURE NEW_PROJECT (id CHAR(5), name VARCHAR(20), product VARCHAR(12)) RETURNS (result VARCHAR(30), num smallint) AS DECLARE VARIABLE emp_wo_proj smallint; DECLARE VARIABLE i smallint; BEGIN id = UPPER(id); /* Project id must be in uppercase. */ INSERT INTO PROJECT (PROJ_ID, PROJ_NAME, PRODUCT) VALUES (:id, :name, :product); result = 'New Project Inserted OK.'; SUSPEND; /* Add Employees to the new project */ i =0; result = 'Project Got Employee Number:'; FOR SELECT EMP_NO FROM EMPLOYEE WHERE EMP_NO NOT IN (SELECT EMP_NO FROM EMPLOYEE_PROJECT) INTO :emp_wo_proj DO BEGIN IF(i <3)THEN BEGIN IF (emp_wo_proj = 5) THEN EXCEPTION CEO; EXECUTE PROCEDURE ADD_EMP_PROJ :emp_wo_proj, :id; num = emp_wo_proj; SUSPEND; END ELSE EXIT; i =i +1; WHEN EXCEPTION CEO DO BEGIN EXECUTE PROCEDURE ADD_EMP_PROJ 28, :id; num =28; SUSPEND; END END /* Error Handling */ WHEN SQLCODE -625 DO BEGIN IF ((:product <> 'software') OR (:product <> 'hardware') OR (:product <> 'other') OR (:product <> 'N/A')) THEN result = 'Enter product: software, hardware, other, or N/A'; END WHEN SQLCODE -803 DO result = 'Could not insert into table - Duplicate Value'; END!! SET TERM ;!! This procedure can be called with a statement such as: SELECT * FROM NEW_PROJECT('XYZ', 'Alpha project', 'software'); With results (in isql) such as: RESULT NUM =========================== ====== New Project Inserted OK. Project Got Employee Number: 28 Project Got Employee Number: 29 Project Got Employee Number: 36