https://github.com/subhashchandra-birajdar/spring-procedure-function
stored procedure implemented with database and springboot with gradle. call the procedure and functions.
https://github.com/subhashchandra-birajdar/spring-procedure-function
functions gradle hibernate-jpa java17-spring-boot mysql open-api spring stored-procedures
Last synced: about 2 months ago
JSON representation
stored procedure implemented with database and springboot with gradle. call the procedure and functions.
- Host: GitHub
- URL: https://github.com/subhashchandra-birajdar/spring-procedure-function
- Owner: Subhashchandra-Birajdar
- Created: 2025-01-21T09:21:04.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-01-21T09:34:26.000Z (11 months ago)
- Last Synced: 2025-07-28T06:03:06.831Z (5 months ago)
- Topics: functions, gradle, hibernate-jpa, java17-spring-boot, mysql, open-api, spring, stored-procedures
- Language: Java
- Homepage:
- Size: 49.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spring-procedure-function

update_stock:
--------------
```
CREATE DEFINER=`root`@`localhost` PROCEDURE `update_stock`(
IN productId INT,
IN quantity INT
)
BEGIN
UPDATE product
SET stock_quantity = stock_quantity - quantity
WHERE id = productId;
END
```
# call the stored procedure in database level
```
call procedure_function.update_stock(1, 5);
```
get_total_price:
----------------
```
CREATE DEFINER=`root`@`localhost` FUNCTION `get_total_price`(productId INT) RETURNS decimal(10,2)
READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE total DECIMAL(10,2);
SELECT SUM(price*stock_quantity) INTO total
FROM Product
WHERE id = productId;
RETURN total;
END
```
# call the function in database level
```
select procedure_function.get_total_price(1);
```
# swagger GUI
```
http://localhost:8080/swagger-ui.html
```
### Why Use Stored Procedures and Functions?
Complex Logic: If you have complicated SQL operations — like multiple joins or conditional logic — stored procedures can help organize your code.
Performance: Stored procedures sometimes run faster because the database can optimize and cache them.
Security: You can permit to run a stored procedure without allowing direct access to the underlying tables.
Reusability: If many applications or parts of your code need the same SQL logic, you can store it in a procedure or function and call it whenever you want