0% found this document useful (0 votes)
3 views2 pages

Procedure

Uploaded by

pathades585
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Procedure

Uploaded by

pathades585
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

avcoe@avcoe-HP-ProDesk-400-G1-SFF:~$ sudo mysql -u root;

[sudo] password for avcoe:


Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.41-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.

mysql> use Sagar;


Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> CREATE TABLE Employees (
-> EmployeeID INT PRIMARY KEY,
-> Name VARCHAR(50),
-> Salary DECIMAL(10, 2)
-> );
Query OK, 0 rows affected (0.83 sec)

mysql> -- INSERT INTO Employees VALUES (1, 'Alice', 50000.00);


mysql> INSERT INTO Employees VALUES (2, 'Bob', 60000.00);
Query OK, 1 row affected (0.17 sec)

mysql> INSERT INTO Employees VALUES (3, 'Charlie', 55000.00);


Query OK, 1 row affected (0.13 sec)

mysql> DELIMITER $$
mysql>
mysql> CREATE PROCEDURE UpdateSalary(IN p_EmployeeID INT, IN
p_PerformanceRating INT)
-> BEGIN
-> IF p_PerformanceRating = 1 THEN
-> UPDATE Employees
-> SET Salary = Salary * 1.10
-> WHERE EmployeeID = p_EmployeeID;
-> END IF;
-> END $$
Query OK, 0 rows affected (0.20 sec)

mysql> DELIMITER $$
mysql>
mysql> CREATE FUNCTION TotalSalaryExpenditure()
-> RETURNS DECIMAL(10, 2)
-> DETERMINISTIC
-> BEGIN
-> DECLARE total_salary DECIMAL(10, 2);
->
-> -- Calculate total salary expenditure
-> SELECT SUM(Salary) INTO total_salary FROM Employees;
->
-> -- Return the result
-> RETURN total_salary;
-> END$$
Query OK, 0 rows affected (0.13 sec)

mysql>
mysql> DELIMITER ;
mysql> CALL UpdateSalary(1, 1); -- 10% increase for EmployeeID 1
Query OK, 0 rows affected (0.03 sec)

mysql> DELIMITER $$
mysql>
mysql> CREATE PROCEDURE GetTotalSalaryExpenditure()
-> BEGIN
-> DECLARE total DECIMAL(10, 2);
->
-> -- Assuming TotalSalaryExpenditure is a function or calculated
value.
-> SELECT SUM(Salary) INTO total FROM Employees;
->
-> -- Output total salary expenditure
-> SELECT CONCAT('Total Salary Expenditure: ', total) AS
TotalExpenditure;
-> END $$
Query OK, 0 rows affected (0.15 sec)

mysql>
mysql> DELIMITER ;
mysql> CALL GetTotalSalaryExpenditure();
+-------------------------------------+
| TotalExpenditure |
+-------------------------------------+
| Total Salary Expenditure: 115000.00 |
+-------------------------------------+
1 row in set (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

You might also like