Answers for "mysql stored function"

SQL
2

mysql create function

-- MySQL

-- example
DELIMITER $$
CREATE FUNCTION f_employee_count(p_dept_no INTEGER) RETURNS INTEGER
  DETERMINISTIC NO SQL READS SQL DATA
  BEGIN
    DECLARE v_emp_count INTEGER;

    SELECT COUNT(*)
    INTO v_emp_count
    FROM EMPLOYEES E
    WHERE E.DEPT_NO = p_dept_no
    GROUP BY DEPARTMENT_NO;

    RETURN v_emp_count;
END$$
DELIMITER ;

/* syntax:
DELIMITER $$
CREATE FUNCTION <Your-procedure-name>(<arguments>) RETURNS <date-type>
  DETERMINISTIC NO SQL READS SQL DATA
  BEGIN
      DECLARE <variable-name> <data-type>

      <Code-that-sets-the-output-variable>; 

      RETURN <variable-name>;
END$$
DELIMITER ;
*/
Posted by: Guest on May-19-2020
2

MySQL Stored Procedures

DELIMITER $$

CREATE PROCEDURE GetCustomers()
BEGIN
	SELECT 
		customerName, 
		city, 
		state, 
		postalCode, 
		country
	FROM
		customers
	ORDER BY customerName;    
END $$

DELIMITER ;


-- Once you save the stored procedure, you can invoke it by using the CALL statement:

CALL GetCustomers();
Posted by: Guest on May-19-2021

Code answers related to "mysql stored function"

Code answers related to "SQL"

Browse Popular Code Answers by Language