關於使用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匯出表中特定條件的表
- exp匯出報錯EXP-00106問題處理
- oracle資料匯出匯入(exp/imp)Oracle
- Oracle資料庫匯入匯出。imp匯入命令和exp匯出命令Oracle資料庫
- 使用Exp和Expdp匯出資料的效能對比與最佳化
- 關於unity專案匯出iOS工程的問題UnityiOS
- 關於idea匯入gradle工程,出現sync failed的問題IdeaGradleAI
- 關於PHP匯出資料超時的優化PHP優化
- 關於EasyExcel的資料匯入和單sheet和多sheet匯出Excel
- 請教一個關於不確定條件個數搜尋的問題
- Angular 內容投影 content projection 關於條件渲染問題的單步除錯AngularProject除錯
- exp匯出遭遇IMP-00020
- 關於 maatwebsite/excel 匯出不能識別中文檔名稱的問題WebExcel
- 使用imp/exp遇到兩個問題
- MySQL 匯出一條資料的插入語句MySql
- 關於android stdio連線mysql資料庫出現過的問題AndroidMySql資料庫
- 關聯條件的業務使用
- 關於CakeWalk匯出音訊前幾秒聲音過大的問題音訊
- exp和expdp的filesize引數的使用--匯出多個檔案
- 關於java中Excel的匯入匯出JavaExcel
- 【oracle 資料匯入匯出字元問題】Oracle字元
- php不使用Office包實現上萬條資料匯出表格PHP
- 土製Excel匯入匯出及相關問題探討Excel
- 關於使用者 email 郵件地址是否允許有加號的問題AI
- 關於oracle資料庫訊號量的問題Oracle資料庫
- 使用Dbeaver 進行資料的匯入和匯出
- 關於取每個使用者最新一條留言去重的問題
- 關於為前端連線資料庫出現問題答案的尋找(404)前端資料庫
- DBeaver 資料匯入SQL時的問題SQL
- 關於MQTT 使用遇到問題MQQT
- 關於 Safari back 按鈕在 iOS 16 不能按照期望工作的問題分析iOS
- 使用Excel資料進行條件刪除Excel
- 使用csv批量匯入、匯出資料的需求處理
- MySQL 8.0.12 --secure-file-priv 資料匯出問題解決MySql
- 關於回覆資料後,登入不上的問題
- 關於 SAP HANA 資料庫的死鎖問題(deadlock)資料庫
- 如何確定一個dmp檔案是exp匯出的還是expdp匯出的?
- 關於外連線和where條件