package org;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
/**
* @Description:oracle的sql语句转换成mysql的sql语句
* @date 2013-2-17
*/
public class OracleSqlConvert4MysqlSqlTool {
public static void main(String[] args) throws IOException {
String oriPath = "D:\\oracle_path.sql";//oracle sql文件地址
String desPath = "D:\\mysql_path.sql";//mysql sql程序生成目标地址
BufferedReader reader = null;
PrintWriter writer = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(oriPath),"gbk"));
writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(desPath),"utf-8"));
String l;
while ((l = reader.readLine()) != null) {
if (l.startsWith("prompt")) continue;
if (l.startsWith("set"))continue;
if (l.startsWith("values")) {
l = l.replace("dd-mm-yyyy hh24:mi:ss.ff", "%d-%m-%Y %H:%i:%s.%f");
l = l.replace("dd-mm-yyyy hh24:mi:ss", "%d-%m-%Y %H:%i:%s");
l = l.replace("03-01-0001", "03-01-1970");
l = l.replace("01-01-1970", "03-01-1970");
l = l.replace("to_date", "str_to_date");
l = l.replace("to_timestamp", "str_to_date");
l = l.replace("' || chr(10) || '", " ");
l = l.replace("' || chr(13) || '", " ");
}
writer.println(l);
}
} finally {
if (reader != null) {
reader.close();
}
if (writer != null) {
writer.close();
}
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
前往页