- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Call Stored Procedures within a Stored Procedure with IF Logic?
To call stored procedures within a stored procedure, the syntax is as follows −
If yourInputValue > 100 then call yourProcedureName1(); else call yourProcedureName2(); end If ; END
Let us implement the above syntax. In order to implement the above concept, let us create a stored procedure −
mysql> delimiter // mysql> create procedure Hello_Stored_Procedure() -> BEGIN -> select 'Hello World!!!'; -> END -> // Query OK, 0 rows affected (0.18 sec)
The query to create the second stored procedure is as follows −
mysql> create procedure Hi_Stored_Procedure() -> BEGIN -> select 'Hi!!!'; -> END -> // Query OK, 0 rows affected (0.17 sec)
Here is the query to call stored procedures within a stored procedure with IF logic −
mysql> DELIMITER // mysql> create procedure test(IN input int) -> BEGIN -> If input > 100 then -> call Hello_Stored_Procedure(); -> else -> call Hi_Stored_Procedure(); -> end If ; -> END -> // Query OK, 0 rows affected (0.18 sec)
Now you can call the stored procedure with the help of call −
mysql> delimiter ; mysql> call test(110);
This will produce the following output −
+----------------+ | Hello World!!! | +----------------+ | Hello World!!! | +----------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec)
- What are stored procedures? How to call stored procedures using JDBC program?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- What is stored procedure and how can we create MySQL stored procedures?
- Insert values in two tables with a single stored procedure call in MySQL
- How to call a stored procedure using select statement in MySQL?
- MySQL procedure to call multiple procedures?
- MySQL Sum Query with IF Condition using Stored Procedure
- How to call a stored procedure using callable statement in JDBC explain?
- Create a stored Procedures using MySQL Workbench?
- How can a COBOL-DB2 program call a STORED PROCEDURE? Give an example.
- Create a stored procedure with delimiter in MySQL
- What are Stored procedures in JDBC?
- How to call an existing stored procedure in a database using JDBC API?
- How to call a stored procedure that accepts input parameters, using JDBC program?
- How to call a stored procedure that returns output parameters, using JDBC program?