欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

oracle數(shù)據(jù)與文本導入導出源碼示例

 更新時間:2017年10月13日 16:13:06   投稿:mengwei  
這篇文章主要介紹了oracle數(shù)據(jù)與文本導入導出源碼示例,具有一定參考價值,需要的朋友可以了解下。

oracle提供了sqlldr的工具,有時需要講數(shù)據(jù)導入到文本,oracle的spool可以輕松實現(xiàn)。

方便的實現(xiàn)oracle導出數(shù)據(jù)到txt、txt導入數(shù)據(jù)到oracle。

一、導出數(shù)據(jù)到txt

用all_objects表做測試

SQL> desc all_objects;
 Name                   Null?  Type
 ----------------------------------------- -------- ----------------------------
 OWNER                   NOT NULL VARCHAR2(30)
 OBJECT_NAME                NOT NULL VARCHAR2(30)
 SUBOBJECT_NAME                   VARCHAR2(30)
 OBJECT_ID                 NOT NULL NUMBER
 DATA_OBJECT_ID                   NUMBER
 OBJECT_TYPE                    VARCHAR2(19)
 CREATED                  NOT NULL DATE
 LAST_DDL_TIME               NOT NULL DATE
 TIMESTAMP                     VARCHAR2(19)
 STATUS                       VARCHAR2(7)
 TEMPORARY                     VARCHAR2(1)
 GENERATED                     VARCHAR2(1)
 SECONDARY                     VARCHAR2(1)

拿object_id,object_name做導出、導入測試。

一些設置滿足數(shù)據(jù)導出的樣式:

vi exp_table.sql

set line 1000     --設置行的長度
set pagesize 0    --輸出不換頁
set feedback off   --默認的當一條sql發(fā)出的時候,oracle會給一個反饋,比如說創(chuàng)建表的時候,如果成功命令行會返回類似:Table created的反饋,off后不顯示反饋
set heading off    --不顯示表頭信息
set trimspool on   --如果trimspool設置為on,將移除spool文件中的尾部空
set trims on     --去掉空字符
set echo off;      --顯示start啟動的腳本中的每個sql命令,缺省為on
set colsep '|'     --設置分隔符
set termout off    --不在屏幕上顯示結(jié)果
spool db1.txt     --記錄數(shù)據(jù)到db1.txt
select object_id,object_name from all_objects; --導出數(shù)據(jù)語句
spool off       --收集完畢
exit

一切就緒后導出數(shù)據(jù):

[oracle@centos5 ~]$ sqlplus test/test @exp_table.sql 
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Jun 13 16:35:14 2013
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@centos5 ~]$ sed -i 's/ //g' db1.txt --可選,去除每行開頭部分的空格
[oracle@centos5 ~]$ more db1.txt 20|ICOL$
44|I_USER1
28|CON$
15|UNDO$
29|C_COBJ#
3|I_OBJ#
25|PROXY_ROLE_DATA$

導出后檢查數(shù)據(jù)的記錄數(shù)是否正確

[oracle@centos5 ~]$ cat db1.txt |wc -l
49988
[oracle@centos5 ~]$ sqlplus test/test
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Jun 13 16:36:21 2013
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select count(*) from all_objects;
 COUNT(*)
----------
   49988 --數(shù)據(jù)正確

二、從txt導入數(shù)據(jù)到oracle

sqlldr是通過一個control文件設定后,從文本導入數(shù)據(jù)

建立一張測試表

SQL> create table tb_sqlldr (id number,name varchar2(50));
Table created.

建立一個control文件

vi tb_sqlldr.ctl

load data         
infile 'db1.txt'      --數(shù)據(jù)來源文本
append into table tb_sqlldr  --數(shù)據(jù)導入到表tb_sqldr中,導入方式為追加,如果想覆蓋
fields terminated by "|"  --4、字段終止于X'09',是一個制表符(tab)
(id,name)          --定義對應的字段名稱,注意順序

導入數(shù)據(jù)分成四種模式,可以根據(jù)需求選擇:

APPEND // 原先的表有數(shù)據(jù) 就加在后面

INSERT // 裝載空表 如果原先的表有數(shù)據(jù) sqlloader會停止 默認值

REPLACE // 原先的表有數(shù)據(jù) 原先的數(shù)據(jù)會全部刪除

TRUNCATE // 指定的內(nèi)容和replace的相同 會用truncate語句刪除現(xiàn)存數(shù)據(jù)

執(zhí)行導入操作

sqlldr userid=test/test control=tb_sqlldr.ctl

差不多5w的數(shù)據(jù)短短2s解決

執(zhí)行導入后驗證數(shù)據(jù)

SQL> select count(*) from tb_sqlldr;
 COUNT(*)
----------
   49988

導入成功

再執(zhí)行一次導入操作,由于設置為追加:

SQL> select count(*) from tb_sqlldr;
 COUNT(*)
----------
   99976

記錄翻倍

sqlldr還有很多參數(shù)供選擇,比如log、bad這些,查看幫助即可。

[oracle@centos5 ~]$ sqlldr
SQL*Loader: Release 10.2.0.4.0 - Production on Thu Jun 13 17:07:26 2013
Copyright (c) 1982, 2007, Oracle. All rights reserved.

Usage: SQLLDR keyword=value [,keyword=value,...]
Valid Keywords:
  userid -- ORACLE username/password      
  control -- control file name         
    log -- log file name           
    bad -- bad file name           
   data -- data file name           
  discard -- discard file name         
discardmax -- number of discards to allow     (Default all)
   skip -- number of logical records to skip  (Default 0)
   load -- number of logical records to load  (Default all)
  errors -- number of errors to allow      (Default 50)
   rows -- number of rows in conventional path bind array or between direct path data saves
        (Default: Conventional path 64, Direct path all)
 bindsize -- size of conventional path bind array in bytes (Default 256000)
  silent -- suppress messages during run (header,feedback,errors,discards,partitions)
  direct -- use direct path           (Default FALSE)
  parfile -- parameter file: name of file that contains parameter specifications
 parallel -- do parallel load           (Default FALSE)
   file -- file to allocate extents from   
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions (Default FALSE)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as unusable (Default FALSE)
commit_discontinued -- commit loaded rows when load is discontinued (Default FALSE)
 readsize -- size of read buffer         (Default 1048576)
external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE (Default NOT_USED)
columnarrayrows -- number of rows for direct path column array (Default 5000)
streamsize -- size of direct path stream buffer in bytes (Default 256000)
multithreading -- use multithreading in direct path 
 resumable -- enable or disable resumable for current session (Default FALSE)
resumable_name -- text string to help identify resumable statement
resumable_timeout -- wait time (in seconds) for RESUMABLE (Default 7200)
date_cache -- size (in entries) of date conversion cache (Default 1000)
PLEASE NOTE: Command-line parameters may be specified either by
position or by keywords. An example of the former case is 'sqlldr
scott/tiger foo'; an example of the latter is 'sqlldr control=foo
userid=scott/tiger'. One may specify parameters by position before
but not after parameters specified by keywords. For example,
'sqlldr scott/tiger control=foo logfile=log' is allowed, but
'sqlldr scott/tiger control=foo log' is not, even though the
position of the parameter 'log' is correct.

總結(jié)

以上就是本文關于oracle數(shù)據(jù)與文本導入導出源碼示例的全部內(nèi)容,感興趣的朋友可以參閱:ORACLE SQL語句優(yōu)化技術要點解析oracle 數(shù)據(jù)庫啟動階段分析、oracle數(shù)據(jù)庫導入導出命令解析等,如有不足之處,歡迎留言指正,希望對大家有所幫助。感謝大家對腳本之家網(wǎng)站的支持。

相關文章

  • oracle表空間表分區(qū)詳解及oracle表分區(qū)查詢使用方法

    oracle表空間表分區(qū)詳解及oracle表分區(qū)查詢使用方法

    racle表空間表分區(qū)詳解及oracle表分區(qū)查詢使用方法,大家參考使用吧
    2013-12-12
  • Oracle 多行記錄合并/連接/聚合字符串的幾種方法

    Oracle 多行記錄合并/連接/聚合字符串的幾種方法

    怎么合并多行記錄的字符串,一直是oracle新手喜歡問的SQL問題之一,關于這個問題的帖子我看過不下30個了,現(xiàn)在就對這個問題,進行一個總結(jié)。
    2009-11-11
  • Oracle dbca時報:ORA-12547: TNS:lost contact錯誤的解決

    Oracle dbca時報:ORA-12547: TNS:lost contact錯誤的解決

    這篇文章主要給大家介紹了關于Oracle在dbca時報:ORA-12547: TNS:lost contact錯誤的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看吧。
    2017-11-11
  • ORACLE實例的后臺進程

    ORACLE實例的后臺進程

    Oralce實例由內(nèi)存和后臺進程構(gòu)成。實例后臺進程在啟動實例時啟動,在終止實例時終止運行。
    2009-09-09
  • oracle 10g 快照操作方法

    oracle 10g 快照操作方法

    本文將詳細介紹oracle 10g 快照操作方法包括創(chuàng)建、刷新、修改等,需要了解的朋友可以參考下
    2012-12-12
  • Oracle的substr和instr函數(shù)簡單用法

    Oracle的substr和instr函數(shù)簡單用法

    這篇文章主要介紹了Oracle的substr和instr函數(shù)簡單用法 的相關資料,需要的朋友可以參考下
    2015-12-12
  • Oracle安裝遇到INS-30131錯誤的解決方法

    Oracle安裝遇到INS-30131錯誤的解決方法

    這篇文章主要介紹了Oracle安裝遇到錯誤INS-30131的解決方法,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Oracle?ORA-00257:?歸檔程序錯誤解決辦法

    Oracle?ORA-00257:?歸檔程序錯誤解決辦法

    今天發(fā)現(xiàn)oracle數(shù)據(jù)庫連不上,報錯:ORA-00257:歸檔程序錯誤,在釋放之前僅限于內(nèi)部連接?馬上聯(lián)想到可能是空間滿了,一看磁盤目錄果然,這篇文章主要給大家介紹了關于Oracle?ORA-00257:歸檔程序錯誤的解決辦法,需要的朋友可以參考下
    2024-04-04
  • Oracle 12.2處理sysaux空間占滿問題

    Oracle 12.2處理sysaux空間占滿問題

    今天處理別的問題查看告警日志偶然發(fā)現(xiàn)大量的報錯,無法擴展SYSAUX表空間,于是登錄系統(tǒng),查看系統(tǒng)表空間使用情況,發(fā)現(xiàn)SYSAUX表空間用滿了,所以本文給大家介紹了Oracle 12.2處理sysaux空間占滿問題,需要的朋友可以參考下
    2024-02-02
  • rman配置及rman常用命令操作

    rman配置及rman常用命令操作

    這篇文章主要介紹了rman配置及rman常用命令操作,包括校驗備份信息、查看備份、刪除備份等,需要的朋友可以參考下
    2014-03-03

最新評論