- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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?
- MySQL Sum Query with IF Condition using Stored Procedure
- MySQL procedure to call multiple procedures?
- Insert values in two tables with a single stored procedure call in MySQL
- Create a stored Procedures using MySQL Workbench?
- How to call a stored procedure using select statement in MySQL?
- What are Stored procedures in JDBC?
- Create a stored procedure with delimiter in MySQL
- Implement If else in stored procedure in MySQL?
- How to call a stored procedure using callable statement in JDBC explain?
- What is STORED PROCEDURE in a DB2? How will you create a new stored procedure?
- How can a COBOL-DB2 program call a STORED PROCEDURE? Give an example.
- What are the advantages of stored procedures?