MySQL数据库存储过程动态表建立(PREPARE)_MySQL
Release: 2016-06-01 13:12:04
Original
1314 people have browsed it
- PREPARE statement_name FROM sql_text /*定义*/
- EXECUTE statement_name [USING variable [,variable...]] /*执行预处理语句*/
- DEALLOCATE PREPARE statement_name /*删除定义*/
这是我项目当中用到的,用作参考使用:
DELIMITER $$DROP PROCEDURE IF EXISTS `gpsdata`.`sp_test`$$CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_test`( gpstime_ varchar(128), gpsname_ varchar(128), gpsinfo_ varchar(256))BEGINDECLARE tbname varchar(50) DEFAULT '0';DECLARE v_sql varchar(1024) DEFAULT '0';SET v_sql=CONCAT('select * from ', tbname ,' where gpsname = ',gpsname_,' order by gpstime desc limit 1');SET @lastdata = v_sql;PREPARE lastdata FROM @lastdata; EXECUTE lastdata;DEALLOCATE PREPARE lastdata; select v_sql;END$$DELIMITER ;
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31