私はmysqlを初めて使用します.oracleでは、カーソルパラメータを使用して達成できます。
印刷したい
OUTPUT :
Department number
10
EMPLOYEE DETAILS
Ravi Kumar 3000 10
vijay Kumar 5000 10
Department number
20
EMPLOYEE DETAILS
John NULL 3000 10
以下は私のコードです
CREATE PROCEDURE xx_dept_emp_dtls(OUT X_STATUS VARCHAR(200))
BEGIN
DECLARE l_department_id
,l_employee_id
,l_dept_id INT ;
DECLARE l_first_name
,l_last_name
,l_job_id VARCHAR(50) ;
DECLARE d BOOLEAN DEFAULT FALSE ;
DECLARE cur_dept CURSOR FOR SELECT department_id FROM dept WHERE DEPARTMENT_ID in(SELECT DEPARTMENT_ID FROM EMP);
DECLARE cur_emp CURSOR FOR SELECT first_name,last_name,last_name FROM EMP WHERE department_id =l_department_id ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET d = TRUE ;
DECLARE CONTINUE HANDLER FOR 1329 SET X_STATUS = 'error' ;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT 'PROGRAM ERROR PLEASE CHECK';
SELECT 1;
OPEN cur_dept ;
l_dept: LOOP
FETCH cur_dept INTO l_department_id ;
IF d then
CLOSE cur_dept ;
Leave l_dept ;
END IF ;
SELECT l_department_id ;
OPEN cur_emp ;
l_emp: LOOP
SELECT 2;
FETCH cur_emp INTO l_first_name
,l_last_name
,l_job_id
;
IF d then
CLOSE cur_emp ;
Leave l_emp ;
END IF ;
SELECT l_first_name
,l_last_name
,l_job_id
,l_dept_id ;
END LOOP l_emp;
END LOOP l_dept;
END ;
最初のレコードが来るので、
上記の出力から私を助けてください