

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can a MySQL stored procedure call another MySQL stored procedure inside it?
It is quite possible that a MySQL stored procedure can call another MySQL stored procedure inside it. To demonstrate it, we are taking an example in which a stored procedure will call another stored procedure to find out the last_insert_id.
Example
mysql> Create table employee.tbl(Id INT NOT NULL AUTO_INCREMENT, Name Varchar(30) NOT NULL, PRIMARY KEY(id))// Query OK, 0 rows affected (3.87 sec) mysql> Create Procedure insert1() -> BEGIN insert into employee.tbl(name) values ('Ram'); -> END// Query OK, 0 rows affected (0.10 sec)
Now, in the next procedure insert2() we will call the 1st stored procedure i.e. insert1().
mysql> Create Procedure insert2() -> BEGIN -> CALL insert1(); -> Select last_insert_id(); -> END // Query OK, 0 rows affected (0.11 sec) mysql> Delimiter ; mysql> Call insert2(); +------------------+ | last_insert_id() | +------------------+ | 1 | +------------------+ 1 row in set (0.36 sec) Query OK, 0 rows affected (0.37 sec)
The above result set shows that when we call insert1() then it inserted the first value in the table called employee.tbl and when we select last_insert_id() in 2nd stored procedure i.e. insert2() then it gives the output 1.
- Related Questions & Answers
- How can we perform START transactions inside MySQL stored procedure?
- How can we perform COMMIT transactions inside MySQL stored procedure?
- How can we perform ROLLBACK transactions inside a MySQL stored procedure?
- How can we handle a result set inside MySQL stored procedure?
- How can we invoke MySQL stored procedure?
- How can we alter a MySQL stored procedure?
- How can we drop a MySQL stored procedure?
- Implement Dynamic SQL query inside a MySQL stored procedure?
- MySQL stored-procedure: out parameter?
- MySQL stored procedure return value?
- How to call a stored procedure using select statement in MySQL?
- What is stored procedure and how can we create MySQL stored procedures?
- Call Stored Procedures within a Stored Procedure with IF Logic?
- Display description of MySQL stored procedure
- How can we write MySQL handler in a stored procedure?
Advertisements