mysql 存储过程
2022/4/22 19:16:25
本文主要是介绍mysql 存储过程,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
--alter table shiyanshuju.gdpoint add S_X_S1 double(10,3),add S_Y_S1 double(10,3),add E_X_S1 double(10,3),add E_Y_S1 double(10,3),add S_H_S1 float(9,3),add E_H_S1 float(9,3),add SE_S1 VARCHAR(255),
add D_S_S1 VARCHAR(20),add E_Deep_S1 double(10,3),add S_Deep_S1 double(10,3),add D_Type_S1 VARCHAR(20);--
存储过程调用 方法
call delColoums (1,2) --参数 字段排序开始,字段排序结束 call addColoums(1,1)
**** 存储过程 1:循环增加字段****
DROP PROCEDURE IF EXISTS `hd_ybz`.`addColoums`; CREATE DEFINER=`root`@`localhost` PROCEDURE `addColoums`(IN `startnum` int,IN `endnum` int) BEGIN DECLARE num int default 1; WHILE startnum <= endnum DO set @addSql = CONCAT('alter table shiyanshuju.gdpoint add S_X_S',startnum,' double(10,3), add S_Y_S',startnum,' double(10,3),add E_X_S',startnum,' double(10,3),add E_Y_S',startnum,' double(10,3),add S_H_S',startnum,' float(9,3),add E_H_S',startnum,' float(9,3),add SE_S',startnum,' VARCHAR(255), add D_S_S',startnum,' VARCHAR(20),add E_Deep_S',startnum,' double(10,3),add S_Deep_S',startnum,' double(10,3),add D_Type_S',startnum,' VARCHAR(20)'); prepare addstmt from @addSql; execute addstmt; DEALLOCATE PREPARE addstmt; set startnum = (startnum+num); END WHILE; IF startnum > endnum THEN set startnum = endnum; END IF ; SELECT CONCAT('增加字段PROCEDURE执行完毕:',startnum) result; END;
**** 存储过程 2: 循环删除字段***
DROP PROCEDURE IF EXISTS `hd_ybz`.`delColoums`; CREATE DEFINER=`root`@`localhost` PROCEDURE `delColoums`(IN `startnum` int,IN `endnum` int) BEGIN DECLARE num int default 1; WHILE startnum <= endnum DO set @delSql = CONCAT('alter table shiyanshuju.gdpoint drop column S_X_S',startnum,' ,drop column S_Y_S',startnum,' ,drop column E_X_S',startnum,' ,drop column E_Y_S',startnum,' ,drop column S_H_S',startnum,' ,drop column E_H_S',startnum,' ,drop column SE_S',startnum,', drop column D_S_S',startnum,',drop column E_Deep_S',startnum,',drop column S_Deep_S',startnum,',drop column D_Type_S',startnum,''); prepare delstmt from @delSql; execute delstmt; DEALLOCATE PREPARE delstmt; set startnum = (startnum+num); END WHILE; IF startnum > endnum THEN set startnum = endnum; END IF ; SELECT CONCAT('删除字段PROCEDURE执行完毕:',startnum) result; END;
这篇关于mysql 存储过程的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-02MySQL 3主集群搭建
- 2024-12-25如何部署MySQL集群资料:新手入门教程
- 2024-12-24MySQL集群部署资料:新手入门教程
- 2024-12-24MySQL集群资料详解:新手入门教程
- 2024-12-24MySQL集群部署入门教程
- 2024-12-24部署MySQL集群学习:新手入门教程
- 2024-12-24部署MySQL集群入门:一步一步搭建指南
- 2024-12-07MySQL读写分离入门:轻松掌握数据库读写分离技术
- 2024-12-07MySQL读写分离入门教程
- 2024-12-07MySQL分库分表入门详解