MySQL Forums :: Stored Procedures :: passing a table as a INPUT parameter to a stored procedure


Advanced Search

Re: passing a table as a INPUT parameter to a stored procedure
Posted by: B Aneja ()
Date: June 17, 2016 07:28PM

Hey, I enclosed the most recent code, updated after suggestions from you for the procedure I wrote. Could you please look at it once and let me know what you think is wrong with it.

delimiter $$

drop procedure if exists dyn_sql$$

CREATE procedure dyn_sql(in_table_name VARCHAR(100)
,out output_table varchar(30)
,out status_code INT
,out status_msg varchar(100))

BEGIN
DECLARE l_sql_stmt varchar (1000);
DECLARE l_student_id INT;


BEGIN

SET @l_student_id=in_student_id;

SET @l_sql_stmt = CONCAT('CREATE TABLE TEMP_TABLE AS '
' SELECT S.STUDENT_ID,SC.SUM(SCORE),SC.AVG(SCORE),SC.MAX(SCORE),SC.MIN(SCORE) '
' FROM STUDENT S,', in_table_name,' AS SCORE SC '
' WHERE S.STUDENT_ID = SC.STUDENT_ID '
' AND S.STUDENT_ID=? '
' GROUP BY SC.EVENT_ID ');

SELECT @l_sql_stmt;

prepare stmt from @l_sql_stmt;
execute stmt using @l_student_id;

SET OUTPUT_TABLE :='TEMP_TABLE';
SET status_code :=0;
SET STATUS_MSG :=' SUCCCESS!';

END;

END$$
DELIMITER ;

Options: ReplyQuote


Subject Views Written By Posted
passing a table as a INPUT parameter to a stored procedure 3502 B Aneja 06/17/2016 02:18AM
Re: passing a table as a INPUT parameter to a stored procedure 427 Peter Brawley 06/17/2016 05:38AM
Re: passing a table as a INPUT parameter to a stored procedure 396 B Aneja 06/17/2016 01:40PM
Re: passing a table as a INPUT parameter to a stored procedure 355 Peter Brawley 06/17/2016 02:56PM
Re: passing a table as a INPUT parameter to a stored procedure 361 B Aneja 06/17/2016 03:53PM
Re: passing a table as a INPUT parameter to a stored procedure 361 B Aneja 06/17/2016 07:28PM
Re: passing a table as a INPUT parameter to a stored procedure 372 Peter Brawley 06/18/2016 11:14AM
Re: passing a table as a INPUT parameter to a stored procedure 356 Rick James 07/09/2016 10:57PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.