oracle数据迁移到 mysql
来源:互联网 发布:汽车保养提醒软件 编辑:程序博客网 时间:2024/04/26 23:26
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
public class TestSql
{
public static void main(String[] args) throws Exception{
// String paraSql="provider_id in(select p.provider_id from t_provider p where p.attribution_id = 1)";
// String bmsTables="t_provider@attribution_id=1,t_provider_contact@"+paraSql+",t_operator@"+paraSql+",t_content_provider@"+paraSql+","+
// "t_service_provider@"+paraSql+",T_PROVIDER_BUSINESS@"+paraSql+","+
// "T_PROSPEC_R,T_PROD_RESOURCE_R,t_productoffering_r,"+
// "t_price_policy,t_prodoffering_price_r,t_promotion_policy,t_prodoffering_promotion_r";
// String ip="172.20.14.6";
// String user="bmsb036gd_0716";
String iepgmTables="T_COLUMN@parent_id!=0,T_IEPG_ASSET,T_IEPG_ASSET_FILE,T_IEPG_CHANNEL_TYPE,T_IEPG_CHANNEL,T_IEPG_CHANNEL_TYPE_RELATION,T_IEPG_GOODS" +
",T_IEPG_PROGRAM_GUIDE,T_IEPG_PROVIDER,T_NPVR_RECORD,T_PRODOFFERING,T_PO_RESOURCE,T_REGION_FREQ,T_RESOURCE_POSTER,T_RES_COLUMN_MAP,T_USERINFO,T_USER_RECOMMAND";
String ip="172.20.100.25";
String user="sdp_xxx_b052";
printSql(iepgmTables,ip,user,"xxxxxx");
}
private static void printSql(String tables,String ip,String user,String pass) throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = null;
try{
con = DriverManager.getConnection("jdbc:oracle:thin:@"+ip+":1521:orcl",user,pass);
Map<String ,Object> tempMap = new HashMap<String ,Object>();
for(String table : tables.split(",")){
if(tempMap.containsKey(table)){
continue;
}else{
tempMap.put(table, table);
}
String[] tw = table.split("@");
table = tw[0];
String where =null;
if(tw.length==2){
where = tw[1];
}
String gen = getSql(con, table,where,user);
System.out.println(gen);
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
if(con!=null) con.close();
}
}
private static String getSql(Connection con,String table,String where,String owner)throws Exception{
String sql="select column_name,data_type from all_tab_columns where table_name='"+table.toUpperCase()+"' AND owner='"+owner.toUpperCase()+"'";
ResultSet rs = con.createStatement().executeQuery(sql);
String gen="select 'insert into "+table.toLowerCase()+"(`";
List<String> cols = new ArrayList<String>();
List<String> values = new ArrayList<String>();
while(rs.next()){
String col = rs.getString("COLUMN_NAME");
cols.add(col);
String type= rs.getString("DATA_TYPE");
if(type.contains("DATE")||type.contains("TIME")){
values.add("'||decode("+col+",null,'null',''''||to_char("+col+",'yyyy-mm-dd hh24:mi:ss')||'''')||'");
}else if(type.contains("CHAR")){
values.add("'||decode("+col+",null,'null',''''||"+col+"||'''')||'");
}else if(type.contains("NUMBER")){
values.add("'||decode("+col+",null,'null',"+col+")||'");
}
}
gen += StringUtils.join(cols.toArray(),"`,`")+"`) values (";
gen += StringUtils.join(values.toArray(),",")+");' from "+table+(where==null?"":" where "+where)+";";
return gen;
}
}
0 0
- mysql数据迁移到oracle
- oracle数据迁移到 mysql
- oracle数据迁移到mysql数据
- Oracle到MySQL迁移小记(数据部分)
- oracle到mysql的数据迁移
- 数据迁移,从mysql到Oracle
- MYSQL数据迁移到ORACLE、SQLSERVER
- Oracle表数据迁移到mysql
- GoldenGate从oracle迁移数据到mysql
- ORACLE 迁移到MYSQL
- 数据从MySQL迁移到Oracle需要注意些什么
- 数据从MySQL迁移到 Oracle的注意事项
- 用squldr2进行Oracle到MySQL的数据迁移
- 将数据从MySQL迁移到Oracle的注意事项
- 将数据从MySQL迁移到Oracle的注意事项
- 将数据从MySQL迁移到Oracle的注意事项
- Oracle数据库数据迁移到MySQL数据库时间格式问题
- hive元数据从mysql迁移到oracle
- 多生产者和多消费者
- linux线程间通信之信号量
- 读书的意义—献给第19个世界读书日
- 11
- “准公公”恋上“亲家母”胁迫其同床14年被杀
- oracle数据迁移到 mysql
- Triangle
- 11
- 谈谈从PC端到移动端的产品设计差异
- 线程的生命周期
- Android 开发时有关R文件的问题
- Android网络连接之HttpURLConnection和HttpClient
- ARM与X86不具备可比性 [转自 魅族论坛]
- 存储名词科普