title: Getting errors when calling functions inside stored procedure
body: <p>I am writing a stored procedure to manage leaves of employees in a company. Leave should be credited to each employee periodically. </p>
  
  <p>My code is as follows</p>
  
  <pre><code>DROP FUNCTION IF EXISTS inserter;
  
  DELIMITER $$;
  CREATE FUNCTION inserter(emp_id bigint, lpc_id int) RETURNS boolean DETERMINISTIC
  BEGIN
      INSERT INTO aaa_test (aaa_emp_id,aaa_lpc_id) 
      VALUES (emp_id,lpc_id);   
  
      RETURN 1;
  END $$;
  DELIMITER ;
  
  DROP PROCEDURE IF EXISTS start_credit_test;
  
  DELIMITER $$;
  
  CREATE PROCEDURE start_credit_test()
  BEGIN
      DECLARE v_finished INT(11) DEFAULT 0;
      DECLARE my_lpc_id INT(11) DEFAULT 0;
      DECLARE my_emp_id BIGINT(20) DEFAULT 0;
  
      DECLARE emp_cursor CURSOR FOR 
          SELECT lpc_id, emp_id  
          FROM erp_leave_policy, erp_employees, erp_clients, erp_employee_leave_policy 
          WHERE emp_status = 1 
            AND cli_status = 1 
            AND lpc_status = 1 
            AND emp_id = elp_fk_employees 
            AND lpc_id = elp_fk_leave_policy 
            AND cli_id = emp_fk_clients;
  
      DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
  
      OPEN emp_cursor;
  
      get_emp: LOOP
  
          FETCH emp_cursor INTO my_lpc_id,my_emp_id;
  
          IF v_finished = 1 THEN 
              LEAVE get_emp;
          END IF;
  
          call inserter(my_emp_id,my_lpc_id);  
  
     END LOOP get_emp;
  
     CLOSE emp_cursor;
  
  END $$;
  DELIMITER ; 
  </code></pre>
  
  <p>I am using codeigniter. Then when I do </p>
  
  <pre><code>$this-&gt;db-&gt;query("CALL start_credit_test();");
  </code></pre>
  
  <p>I'm getting an error:</p>
  
  <blockquote>
    <p>PROCEDURE abn_erp.inserter does not exist</p>
  </blockquote>
  
  <p>The query inside the procedure </p>
  
  <pre><code>SELECT lpc_id, emp_id  
  FROM erp_leave_policy, erp_employees, erp_clients, erp_employee_leave_policy 
  WHERE emp_status = 1 
    AND cli_status = 1 
    AND lpc_status = 1 
    AND emp_id = elp_fk_employees 
    AND lpc_id = elp_fk_leave_policy 
    AND cli_id = emp_fk_clients;
  </code></pre>
  
  <p>returns the output:</p>
  
  <p><a href="https://i.stack.imgur.com/HzkyV.png" rel="nofollow noreferrer">Click Here</a></p>
  
  <p>Then I inserted function again as</p>
  
  <pre><code>            DELIMITER $$;
              CREATE FUNCTION inserter(emp_id bigint, lpc_id int) RETURNS boolean DETERMINISTIC
              BEGIN
  
                  INSERT INTO aaa_test (aaa_emp_id,aaa_lpc_id) VALUES (emp_id,lpc_id);   
  
                  RETURN 1;
              END $$;
              DELIMITER ;
  </code></pre>
  
  <p>But it shows the error <code>#1304 - FUNCTION inserter already exists</code></p>