mysql 可重复执行添加列
Posted frank_quan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 可重复执行添加列相关的知识,希望对你有一定的参考价值。
DROP PROCEDURE IF EXISTS `add_column_if`; CREATE PROCEDURE `add_column_if`(IN v_table varchar(50), IN v_column varchar(50),IN v_discription varchar(1000)) begin declare stmt varchar(2000); declare v_flag int; select count(*) into v_flag from information_schema.columns where table_schema = (select DATABASE()) and table_name = v_table and column_name = v_column; if(v_flag=0) then set @sqlstr = concat(‘ALTER TABLE `‘,v_table,‘` ADD COLUMN `‘,v_column,‘` ‘,v_discription); prepare stmt from @sqlstr; execute stmt; end if; commit; end ;
调用:
call add_column_if(‘xxx‘,‘xxx‘,‘xxx‘);
以上是关于mysql 可重复执行添加列的主要内容,如果未能解决你的问题,请参考以下文章
spark关于join后有重复列的问题(org.apache.spark.sql.AnalysisException: Reference '*' is ambiguous)(代码片段