exp\imp 遇到作業系統轉移字元問題(比如query引數裡的where)

perfychi發表於2014-02-13

from:baidu.com
String cmd="exp 使用者名稱/密碼@服務名 file=C:\20111226160758.dmp tables=(表名)  query=\\\"where ADDTIME>=to_date('2011-12-01 15:56:46','YYYY-MM-DD hh24:mi:ss') and ADDTIME<=to_date('2011-12-26 15:56:46','YYYY-MM-DD hh24:mi:ss')\\\"";(win7測試透過)

//如果是windows os?

cmd="cmd /c "+cmd;

//如果是linux os

boolean shouldClose=false;
  Process process=null;
  try {
   process = java.lang.Runtime.getRuntime().exec("cmd /c "+cmd);
   BufferedReader b = new BufferedReader(new InputStreamReader(process.getErrorStream()));  
   String line = null;
   boolean err=false;
   errinfo="";
   while((line=b.readLine())!=null)  
   {  
         System.out.println(line);
         if(err)
         {
          errinfo=line;
          process.destroy();
          break;
         }
         if(line.indexOf("錯誤")>0)
         {
          err=true;        
         }
      }  
      int value= process.exitValue();  
      if(value==0||(value==3&&!err))  
      {  
       this.setOperateStatus("資料庫備份完成");
          System.out.println("資料庫備份完成!");  
      } 
      else 
      {  
          System.out.println("exit value =" + value);  
          System.out.println("資料庫備份失敗!");
          this.setOperateStatus("資料庫備份失敗");
      }
      shouldClose=true;
      if(shouldClose)
             process.destroy();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   shouldClose=true;
   e.printStackTrace();
  }finally{   
    try {
     if(process!=null)
     process.waitFor();
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
  }

 query 引數說明

其實文件中講得很清楚:

exp scott/tiger TABLES=emp QUERY=\"WHERE job=\'SALESMAN\' and sal \<1600\"Note:
Because the value of the QUERY parameter contains blanks, most operating systems require that the entire strings WHERE job=\'SALESMAN\' and sal\<1600 be placed in double quotation marks or marked as a literal by some method. Operating system reserved characters also need to be preceded by an escape character. See your Oracle operating system-specific documentation for information about special and reserved characters on your system.

所有作業系統保留字元都要使用轉義符號,看來 ( ) 也需要轉義。

正確的寫法:

 exp scott/tiger tables=skytest file=test.dmp query=\"where dt=to_date\(\'2007-09-22\',\'yyyy-mm-dd\'\)\" (linux)

exp scott/tiger tables=skytest file=test.dmp query=\"where dt=to_date('2007-09-22','yyyy-mm-dd')\" (win7)

任何 os 平臺都適用的方法(推薦):
使用 parfile 就不用擔心這些格式問題

oracle DBALNP01 > cat > test.par
tables=skytest
file=test.dmp
query="where dt=to_date('2007-09-22','yyyy-mm-dd')"

oracle DBALNP01 > exp / parfile=test.par

Export: Release 8.1.7.4.0 - Production on Wed Sep 12 04:22:27 2007

(c) Copyright 2000 Oracle Corporation.  All rights reserved.


Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
With the Partitioning option
JServer Release 8.1.7.4.0 - Production
Export done in US7ASCII character set and US7ASCII NCHAR character set

About to export specified tables via Conventional Path ...
. . exporting table                        SKYTEST          1 rows exported
Export terminated successfully without warnings.

不需要任何轉義符既簡潔又可以在多種作業系統平臺上通用,推薦使用這種方式。

?命令列exp 匯出時對密碼中含的處理方法

使用者的密碼為Rdy)Jl!S

在windows      D:>exp testuser/Rdy)Jl!S@oralocal owner=testuser

在linux    nunix下,用""
$ exp "testuser/Rdy)Jl!S" owner=testuser


IMPDP FLASHBACK_TIME 中如何使用TO_TIMESTAMP引數,防止LRM-00116

官方文件上查,引數檔案中這樣寫"to_timestamp()"

在命令列中直接這樣寫

C:\Documents and Settings\yyy>impdp scott/tiger tables=t directory=exp_dir network_link=test flashback_time="to_timestamp('2009-01-07 2
0:01:22','yyyy-mm-dd hh24:MI:SS')"
LRM-00116: ')'後跟 'yyyy-mm-dd hh24:' 時出現語法錯誤

總提示語法錯誤

後來N長時間終於找到了解決辦法

Alternatively you can used FLASHBACK_TIME parameter like on unix,
flashback_time=\"TO_TIMESTAMP\(\'16-05-2008 11:21:42\', \'DD-MM-YYYY HH24:MI:SS\'\)\"


On windows,
flashback_time=\"TO_TIMESTAMP('16-05-2008 13:24:26', 'DD-MM-YYYY HH24:MI:SS')\"


Use backslash(\) before special character.

所以改成

C:\Documents and Settings\jiachliu>impdp scott/tiger tables=t directory=exp_dir network_link=test flashback_time=\"to_timestamp('2009-01-07
20:01:22','yyyy-mm-dd hh24:MI:SS')\"

執行成功

--END

 
exp\imp 遇到作業系統轉移字元問題(比如query引數裡的where)java_exp命令備份資料庫_query.docx

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27042095/viewspace-1080708/,如需轉載,請註明出處,否則將追究法律責任。

相關文章