title: Mysql Cursor Parameter
body: <p>I am new to mysql ,in oracle we can achieve by using cursor parameter .</p>
  
  <p>I want to print </p>
  
  <pre><code>OUTPUT :
  Department number
  10 
  EMPLOYEE DETAILS
  Ravi  Kumar  3000  10
  vijay Kumar  5000  10
  Department number
  20 
  EMPLOYEE DETAILS
  John  NULL  3000  10
  </code></pre>
  
  <p>Below is my code </p>
  
  <pre><code>       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 ; 
  </code></pre>
  
  <p>So its coming for first record<br>
  Please help me out from above output</p>