DROP TABLE IF EXISTS `test`.`tbl_sp`;
CREATE TABLE `test`.`tbl_sp` (
`SEQ` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`DATA` VARCHAR(45) DEFAULT NULL,
PRIMARY KEY (`SEQ`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;
SELECT * FROM tbl_sp
INSERT INTO test.tbl_sp(DATA)
VALUES
('mysql'),
('java'),
('hibernate'),
('spring'),
('zapatec'),
('jexcel'),
('iReport'),
('json')
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`spDynamicQuery` $$
CREATE PROCEDURE `test`.`spDynamicQuery` (IN szData VARCHAR(50))
BEGIN
SET @QUERY='SELECT * FROM test.tbl_sp WHERE DATA LIKE ?';
SET @DATA = CONCAT('%',szData,'%');
PREPARE stmt FROM @QUERY;
EXECUTE stmt USING @DATA;
DROP PREPARE stm
DELIMITER ;
END $$
CALL spDynamicQuery ('j')
| Style : Background0, Font0, Size16 |