Export specified table to a CSV file
依需執行下列步驟:
- 執行 gen_tab2csv.sql
- 編修 csv_${OWNER}.{TABLE}.sql
- 執行 csv_${OWNER}.{TABLE}.sql
gen_tab2csv.sql:
reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)Callstack:
at User:Alang/IT_專案工作/Oracle_DBA_筆記/Table_to_CSV_file
MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException: reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown.
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptVar expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptVar.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Evaluate (MindTouch.Deki.Script.Expr.DekiScriptAccess expr, DekiScriptExpressionEvaluationState state, Boolean evaluateProperties) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptAccess expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptAccess.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptCall expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptCall.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptSequence expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptSequence.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptReturnScope expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
執行方式
$> sqlplus system/yourpass @gen_tab2csv.sql
NOTE:
- 需要輸入要導出的 OWNER 與 TABLE 名稱
- 執行完後,會在現行目錄內自動建立 csv_${OWNER}.${TABLE}.sql 的 SQL 檔案
執行
$> sqlplus -s system/yourpass @csv_WIN_FDC_STDB.SYSSETTING.sql | tee WIN_FDC_STDB.SYSSETTING.csv
xxx.csv 就是最後的結果。
重要:
為了確保 CSV 檔的每一行內容不會被斷行,可以使用筆數與行數來檢查。
統計 Table 筆數
Table 筆數
SQL> select count(*) from WIN_FDC_STDB.SYSSETTING;
統計 CSV 的輸出行數
$> wc -l WIN_FDC_STDB.SYSSETTING.csv
TIPs:
兩者必須確保是一樣的,如果不同,表示 CSV 檔有某幾行內容被斷行,修改 csv_XXX.sql 的
set linesize 800
將值調大,然後重新導出 CSV ,直到行數與筆數相同為止。