關於使用exp按照條件匯出資料的問題(摘)
昨天需要按照條件匯出一個表,再匯入另一個資料庫,很自然想到了 exp 的 query 引數,本來以為可以很順利完成,結果 query 引數的格式怎麼也寫不對,因為時間緊迫,最後透過 dblink 直接插入了另一個資料庫。今天回過頭來再研究了一下,發現其實也不復雜,按照文件還是能很好的解決的。
希望匯出測試表中日期為 2007-09-22 的一條資料:
SQL> select * from skytest;SID DT
---------- -----------------
1 20070913 00:00:00
2 20070914 00:00:00
3 20070915 00:00:00
4 20070916 00:00:00
5 20070917 00:00:00
6 20070918 00:00:00
7 20070919 00:00:00
8 20070920 00:00:00
9 20070921 00:00:00
10 20070922 00:00:00
12 20070924 00:00:00
11 rows selected.
憑印象按照以下格式執行:
exp / tables=skytest file=test.dmp query="where dt=to_date('2007-09-22','yyyy-mm-dd')"結果報錯:
ksh: syntax error: `(' unexpected
其實文件中講得很清楚:
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.
所有作業系統保留字元都要使用轉義符號,看來 ( ) 也需要轉義。
正確的寫法:
oracle DBALNP01 > exp / tables=skytest file=test.dmp query="where dt=to_date('2007-09-22','yyyy-mm-dd')"Export: Release 8.1.7.4.0 - Production on Wed Sep 12 04:30:45 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 setAbout to export specified tables via Conventional Path ...
. . exporting table SKYTEST 1 rows exported
Export terminated successfully without warnings.
簡潔的寫法:
如果環境變數設定合適,就不需要使用 to_date 函式了
oracle DBALNP01 > exp / tables=skytest file=test.dmp query="where dt='20070922'"Export: Release 8.1.7.4.0 - Production on Wed Sep 12 04:25:56 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 setAbout to export specified tables via Conventional Path ...
. . exporting table SKYTEST 1 rows exported
Export terminated successfully without warnings.
任何 os 平臺都適用的方法(推薦):
以上兩種方法並不一定適合其他作業系統,不過使用 parfile 就不用擔心這些格式問題
oracle DBALNP01 > cat > test.par[@more@]
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 setAbout to export specified tables via Conventional Path ...
. . exporting table SKYTEST 1 rows exported
Export terminated successfully without warnings.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7425608/viewspace-1004708/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle按照表條件expdp匯出資料Oracle
- exp匯出一個表中符合查詢條件的資料
- 資料泵過濾匯出資料的where條件
- EXP匯出資料檔名稱重複問題的解決
- 【EXP】使用EXP的QUERY選項匯出表中部分資料
- 資料匯入匯出EXP/IMP
- exp/imp匯出匯入資料
- oracle資料的匯入匯出imp/expOracle
- 使用Oracle 的 imp ,exp 命令實現資料的匯入匯出Oracle
- oracle資料匯出匯入(exp/imp)Oracle
- 資料匯出問題
- SQL Server 按照條件統計雨量資料SQLServer
- Oracle資料匯入匯出imp/exp命令Oracle
- Oracle exp只匯出部分資料Oracle
- exp/imp匯出匯入工具的使用
- 關於全問檢索按照日期的排序問題排序
- EXP邏輯匯出資料的呼叫方式
- Oracle資料匯入匯出imp/exp命令(轉)Oracle
- 使用exp/imp匯出匯入資料(邏輯備份恢復)
- 關於unity專案匯出iOS工程的問題UnityiOS
- 【EXP/IMP】使用EXP /IMP工具“模糊”匯出和匯入
- Oracle exp/imp匯出匯入工具的使用Oracle
- exp匯出報錯EXP-00106問題處理
- Oracle資料庫匯入匯出。imp匯入命令和exp匯出命令Oracle資料庫
- oracle11g 空表不能exp匯出的問題Oracle
- 問問題_Java一次匯出百萬條資料生成excel(web操作)JavaExcelWeb
- 使用Exp和Expdp匯出資料的效能對比與優化優化
- MySQL資料匯入匯出亂碼問題MySql
- 轉:EXP 資料庫資料 QUERY 選項使用問題資料庫
- 關於資料共享的問題
- 關於匯入模式問題模式
- 使用Exp和Expdp匯出資料的效能對比與最佳化
- 關於資料表結構sql檔案匯入mysql資料庫的問題?MySql資料庫
- 關於郵件監控的問題
- 關於PHP匯出資料超時的優化PHP優化
- exp匯出檔案時 字符集設定問題
- 【實驗】【PARTITION】exp匯出分割槽表資料
- MyBatis 基本資料型別條件判斷問題MyBatis資料型別