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

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Procedure Function » Introduction 
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,2NOT 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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.