title: MySQL Stored Procedure with Cursor Error
body: <p>I am trying to write a MySQL stored procedure that (1) inserts values into an Employee table and (2) takes the new employee's department number, scans the Project table for any projects that the department works on and (3) inserts those projects with the employee's SSN into the Works_On table.  </p>
  
  <p>I am attempting to do this with a cursor, but keep running into syntax errors that I cannot figure out.  The current error is at the point that I am declaring the cursor, but I have no idea how to fix it.  I have tried quite a few things and am hoping that someone will be able to see the mistake.</p>
  
  <pre><code>    Use Company
  DELIMITER //
  
  Create Procedure SP_Insert_NewEmployee 
  (
      IN fname varchar(30),
      IN minit char(1),
      IN lname varchar(30),
      IN ssn char(9),
      IN bdate date,
      IN address varchar(50),
      IN sex char(1),
      IN salary decimal(10,1),
      IN super_ssn char(9),
      IN dno int
  )
  Begin
  Declare projectNumber Integer;
  Declare myCursor2 = CURSOR FOR
      SELECT Pnumber
      FROM PROJECT
      Where Dnum = @dno;
  
  #Insert into Employee
  Insert into EMPLOYEE 
      (
          Fname,
          Minit ,
          Lname ,
          Ssn ,
          Bdate ,
          Address ,
          Sex,
          Salary ,
          Super_ssn,
          Dno
      )
  Values
      (
          $fname ,
          $minit ,
          $lname,
          $ssn ,
          $bdate ,
          $address ,
          $sex ,
          $salary ,
          $super_ssn ,
          $dno 
      );
      END
  
  #Find projects by new employee's dept
  
  
  
  
  OPEN myCursor2;
  
  FETCH NEXT 
      FROM myCursor2 
      INTO 
          projectNumber
  
  
  WHILE @@FETCH_STATUS = 0
  
  BEGIN
   Insert Into WORKS_ON
   Values
      (
          ssn,
          projectNumber,
          0
      )
  
   FETCH NEXT 
   FROM myCursor2 
      INTO 
          projectNumber
  END
  
  CLOSE myCursor2;
  DEALLOCATE myCursor2;
  END
  END
  //
  DELIMITER ;
  </code></pre>