MySQL Forums
Forum List  »  Oracle

EXECUTE IMMEDIATE in My sql
Posted by: sudipta batabyal
Date: May 27, 2009 11:30PM

Hi,

In oracle we have execute immediate statement where sql statements can be executed in run time and the output can be stored into a variable. For example

----In Oracle
DECLARE
-- Local variables here
v_Tab_Name VARCHAR2(2000) := 't_Emp';
v_Count NUMBER;
v_Sql VARCHAR2(2000);
BEGIN
-- Test statements here
v_Sql := ' Select count(1) from ' || v_Tab_Name;
EXECUTE IMMEDIATE v_Sql
INTO v_Count;
Dbms_Output.Put_Line(v_Count);
END;


I want to create a similar logic in Mysql. I know in mysql while executing statement using ‘prepare—execute’ clause, where we can pass a variable by 'USING' clause, but how could I store the output into a variable.

BEGIN

---IN Mysql
-- Local variables here
DECLARE v_Tab_Name VARCHAR(2000);
DECLARE v_Count INT;
DECLARE v_Sql VARCHAR(2000);
SET v_Tab_Name='t_je';
SET v_Sql = concat(' Select count(1) from ' , v_Tab_Name);
PREPARE stmt FROM v_Sql;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt;

END;

I want to store the count (i.e value of stmt) into variable v_Count.


It would be really grateful if any one can help me on this.

Thanks & Regards
Sudipta B.

Options: ReplyQuote


Subject
Views
Written By
Posted
EXECUTE IMMEDIATE in My sql
15900
May 27, 2009 11:30PM


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.