如何从Oracle SQL转储中获取数据

时间:2017-03-27 13:14:33

标签: mysql oracle import

我有一个.sql文件(包含用于创建表和插入数据的SQL语句的文本文件),这些文件显然是从Oracle数据库中转储出来的。

我希望将数据(或至少其中一些)导入MySQL数据库。由于某些特定的数据类型,正常导入不起作用。

我该怎么办?我的猜测:

  1. 以某种方式创建Oracle数据库,导入转储,然后发出SQL请求以提取数据。如果是这样,我必须买东西吗?我是否必须为Oracle数据库创建单独的虚拟机?
  2. 查找并替换MySQL特定的东西到MySQL理解的东西。如果有,是否有任何标准方法来翻译VARCHAR2
  3. 等内容

1 个答案:

答案 0 :(得分:0)

事实证明,您可以 Oracle转换为MySQL。这是一个参考页面:Oracle to MySQL Migration - SQLines

就我而言,我必须将if (ActivityCompat.checkSelfPermission(WebViewActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(WebViewActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(WebViewActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } else { downloadFile(); } @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: downloadFile(); break; } } private void downloadFile() { progressBar.setVisibility(View.VISIBLE); DownloadFileTask task = new DownloadFileTask( WebViewActivity.this, mURL, "/download/pdf_file.pdf"); task.startTask(); } @Override public void onFileDownloaded() { progressBar.setVisibility(View.GONE); File file = new File(Environment.getExternalStorageDirectory() .getAbsolutePath() + "/download/pdf_file.pdf"); if (file.exists()) { pdfView.fromFile(file) //.pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default .enableSwipe(true) .swipeHorizontal(true) .enableDoubletap(true) .defaultPage(0) .enableAnnotationRendering(true) .password(null) .scrollHandle(null) .onLoad(new OnLoadCompleteListener() { @Override public void loadComplete(int nbPages) { pdfView.setMinZoom(1f); pdfView.setMidZoom(5f); pdfView.setMaxZoom(10f); pdfView.zoomTo(2f); pdfView.scrollTo(100,0); pdfView.moveTo(0f,0f); } }) .load(); } } public class DownloadFileTask { public static final String TAG = "DownloadFileTask"; private BaseActivity context; private GetTask contentTask; private String url; private String fileName; public DownloadFileTask(BaseActivity context, String url, String fileName) { this.context = context; this.url = url; this.fileName = fileName; } public void startTask() { doRequest(); } private void doRequest() { contentTask = new GetTask(); contentTask.execute(); } private class GetTask extends AsyncTask<String, Integer, String> { @Override protected String doInBackground(String... arg0) { int count; try { Log.d(TAG, "url = " + url); URL _url = new URL(url); URLConnection conection = _url.openConnection(); conection.connect(); InputStream input = new BufferedInputStream(_url.openStream(), 8192); OutputStream output = new FileOutputStream( Environment.getExternalStorageDirectory() + fileName); byte data[] = new byte[1024]; while ((count = input.read(data)) != -1) { output.write(data, 0, count); } output.flush(); output.close(); input.close(); } catch (Exception e) { Log.e("Error: ", e.getMessage()); } return null; } protected void onPostExecute(String data) { context.onFileDownloaded(); } } 之类的内容翻译为NUMBER(13,0)BIGINTNUMBER(12,2)

大表中没有明确说明的内容(但在下面提到)是Oracle语法指定varchar大小的单位。所以我将DECIMAL(12,2)翻译为VARCHAR2(4000 BYTE)

在我的文件中使用了VARCHAR(4000)函数。内置函数表没有说明要做什么,但我将其替换为to_timestamp,因为结果已写入str_to_date字段。

我还有微秒,这些微秒被排除在DATETIME reference on SQLines之外。在一天结束时,to_date变为to_timestamp('01-JAN-00 12.00.13.130000000 AM','DD-MON-RR HH.MI.SSXFF AM')