2
我是mysql新手,在oracle中我們可以通過使用遊標參數來實現。Mysql光標參數
我想打印
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 ;
所以其未來的第一記錄
請幫我從上面的輸出