Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a Stored Procedure in a Stored Procedure in MySQL

I can't find this answer anywhere, but can you call a Stored Procedure from another Stored Procedure in MySQL? I want to get the Identity Value back and use it in the parent Stored Procedure. We can't use FUNCTIONS anymore!

like image 554
Mike Flynn Avatar asked Jun 12 '12 16:06

Mike Flynn


People also ask

Can you call a stored procedure from another stored procedure MySQL?

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.

Can we call a stored procedure inside a stored procedure?

You can call the stored procedure inside another stored procedure; the JavaScript in the outer stored procedure can retrieve and store the output of the inner stored procedure.

Can we call a procedure inside a procedure in SQL?

Answer is Yes.You can call a procedure within a table function as long as the procedure is read only.

How do you call one SP in another SP in MySQL?

Calling one stored program from another is perfectly simple. You do this with the CALL statement, just as you would from the MySQL command-line client. Figure 2-15 shows a simple stored procedure that chooses between two stored procedures based on an input parameter.


1 Answers

CREATE PROCEDURE innerproc(OUT param1 INT) BEGIN  insert into sometable;  SELECT LAST_INSERT_ID() into param1 ; END ----------------------------------- CREATE PROCEDURE outerproc() BEGIN CALL innerproc(@a); // @a gives you the result of innerproc SELECT @a INTO variableinouterproc FROM dual; END 

OUT parameters should help you in getting the values back to the calling procedure.Based on that the solution must be something like this.

like image 77
Ahamed Mustafa M Avatar answered Sep 22 '22 05:09

Ahamed Mustafa M