oracle转Mysql数据库 字段类型 INTEGER(orcle) 转化mysql变为 (decimal) 解决办法
我们需要把decimal 的列批量变为int型 ,那么一个mysql存储过程就可以搞定。
CREATE DEFINER=`zwb`@`%` PROCEDURE `batch_alter_tables_columntype`(
dbname varchar(50),
from_type varchar(32),
to_type varchar(32)
)
begin
declare tbl_name varchar(128);
declare parent_done int(1) default 0;
declare parent_cursor cursor for select table_name from information_schema.`TABLES` where table_type='BASE TABLE' and table_schema=dbname;
declare continue handler for not found set parent_done=1;
open parent_cursor;
parent_loop:loop fetch parent_cursor into tbl_name;
if parent_done=1 then leave parent_loop;
end if;
begin
declare col_name varchar(128);
declare son_done int(1) default 0;
declare sql_for_alter varchar(1024);
declare son_cursor cursor for select column_name from information_schema.`COLUMNS` where CONVERT(table_name using utf8) collate utf8_bin=convert(tbl_name using utf8) and convert(data_type using utf8) collate utf8_bin in (from_type) and table_schema=dbname;
declare continue handler for not found set son_done=1;
open son_cursor;
son_loop:loop fetch son_cursor into col_name;
if son_done=1 then leave son_loop;
end if;
set sql_for_alter=concat("alter table ",tbl_name," modify column ",col_name," ",to_type);
set @sql=sql_for_alter;
prepare stmt from @sql;
execute stmt;
set son_done=0;
end loop son_loop;
close son_cursor;
end;
set parent_done=0;
end loop parent_loop;
close parent_cursor;
end
本文来自博客园,作者:zwbsoft,转载请注明原文链接:https://www.cnblogs.com/zwbsoft/p/13278021.html
电话微信:13514280351
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南