function in mysql workbench code example

Example 1: 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 ;
*/

Example 2: mysql workbench tutorial

/* Answer to: "mysql workbench tutorial" */

/* 
  A very good and detailed tutorial on the MySQL Workbench is here:
  https://www.youtube.com/watch?v=X_umYKqKaF0
  
  You may also see the video below.
*/

Example 3: mysql workbench

/* Answer to: "mysql workbench download" */

/*
  MySQL Workbench is a visual database design tool that integrates
  SQL development, administration, database design, creation and
  maintenance into a single integrated development environment for
  the MySQL database system.

  You can download it here:
  https://dev.mysql.com/downloads/workbench/
*/

Tags:

Sql Example