Using aggregate function in procedure : Introduction « Procedure Function « SQL / MySQL






Using aggregate function in procedure

       

CREATE TABLE EmployeeS_WITH_PARENTS
      (EmployeeNO         INTEGER NOT NULL PRIMARY KEY,
       FATHER_EmployeeNO  INTEGER,
       MOTHER_EmployeeNO  INTEGER)
;

CREATE   TABLE PENALTIES
        (PAYMENTNO      INTEGER      NOT NULL,
         EmployeeNO       INTEGER      NOT NULL,
         PAYMENT_DATE   DATE         NOT NULL,
         AMOUNT         DECIMAL(7,2) NOT NULL,
         PRIMARY KEY    (PAYMENTNO)          );
         
INSERT INTO PENALTIES VALUES (1,  6, '1980-12-08',100);

DELIMITER $$

CREATE PROCEDURE TOTAL_PENALTIES_Employee
   (IN P_EmployeeNO INTEGER,
    OUT TOTAL_PENALTIES DECIMAL(8,2))
BEGIN
   SELECT SUM(AMOUNT)
   INTO   TOTAL_PENALTIES
   FROM   PENALTIES
   WHERE  EmployeeNO = P_EmployeeNO;
END$$

DELIMITER ;


CALL TOTAL_PENALTIES_Employee (27, @TOTAL)
;
drop table Employees_with_parents;
drop table Employees;

   
    
    
    
    
    
    
  








Related examples in the same category

1.Using user-defined function in a select statement
2.Use user-defined function in a select statement to deal with data in a table
3.Use user-defined function in order by clause
4.Use user-defined function in where clause
5.Recursion
6.Determining the Code of an stored procedures
7.Create procedure for definer