title: How to check mysql cursor result null without using a loop
body: <p>I have a mysql function that returns a varchar value. Inside this function I have define a cursor which only gives a single value. This means in my select statement, I have taken a specific value using table primary key combination. Since I know that this cursor only return one value I don't want to add a loop to check whether the cursor return a value or not. </p>
  
  <pre><code>DELIMITER //
  CREATE FUNCTION PROGRAM_API_Get_Name(
          program_id_     VARCHAR(15),
          uni_id_         VARCHAR(15),
          fac_id_         VARCHAR(15)) RETURNS VARCHAR(100)
  BEGIN
  
      DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
      DECLARE degree_name_ VARCHAR(100);
  
      DECLARE get_name_ CURSOR FOR
          SELECT program_name 
              FROM degree_program_tab
              WHERE program_id = program_id_
              AND   uni_id     = uni_id_
              AND   fac_id     = fac_id_;    
  
      OPEN get_name_;
      IF(!done) THEN
          FETCH get_name_ INTO degree_name_;
          CLOSE get_name_;
          RETURN degree_name_;
      END IF;
  
      RETURN NULL;
  
  END//
  </code></pre>
  
  <p>This function gives me the following error</p>
  
  <blockquote>
    <p>Error Code: 1064. You have an error in your SQL syntax; check the
    manual that corresponds to your MySQL server version for the right
    syntax to use near 'BEGIN              DECLARE CONTINUE HANDLER FOR
    NOT FOUND SET done = TRUE;      ' at line 5   0.</p>
  </blockquote>
  
  <p>If you know how to overcome this, Please help me</p>