MySQL Forums
Forum List  »  Stored Procedures

MySQL 5 - Execute Immediate OR Dynamic SQL
Posted by: Lionel BARRE
Date: May 16, 2006 12:19AM

Hi,

I'm working with PL/SQL on Oracle, and I use the "execute immediate" and "DBMS_SQL"

I will doo the same with MySQL Stored Proc with PREPARE, but it give an error : "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 "

If you have an idea or a better code.

Thanks

Lionel

My Code :
---------
#REMARK: "inf_vw_table" is a view based on the Information schema to retreive the TABLE of my schema.

DROP PROCEDURE IF EXISTS com_pr_liba_optimize_table//
CREATE PROCEDURE com_pr_liba_optimize_table(
IN as_uuid varchar(37)
)
BEGIN
DECLARE ln_end INT DEFAULT 0;
DECLARE ls_table VARCHAR(64);
DECLARE ls_appl_name VARCHAR(100) DEFAULT 'com_pr_liba_optimize_table()';

# create cursor
DECLARE cur_table_list CURSOR FOR
SELECT table_name
FROM inf_vw_table;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET ln_end = 1;

OPEN cur_table_list;
REPEAT FETCH cur_table_list INTO ls_table;
# SET @sql_text := CONCAT('OPTIMIZE TABLE ', ls_table, ';');
# PREPARE stmt FROM @sql_text;
SET @sql_text = 'OPTIMIZE TABLE ?';
SET @temp_tb = ls_table;

PREPARE stmt FROM @sql_text;
EXECUTE stmt USING @temp_tb;
DEALLOCATE PREPARE stmt;

UNTIL ln_end = 1
END REPEAT;
CLOSE cur_table_list;
END;
//

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL 5 - Execute Immediate OR Dynamic SQL
18092
May 16, 2006 12:19AM


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.