oracle提供了sqlldr的工具,有时需要讲数据导入到文本,oracle的spool可以轻松实现。
@H_403_2@
方便的实现oracle导出数据到txt、txt导入数据到oracle。
@H_403_2@
一、导出数据到txt
@H_403_2@
用all_objects表做测试@H_403_2@
拿object_id,object_name做导出、导入测试。
@H_403_2@
一些设置满足数据导出的样式:
@H_403_2@
一切就绪后导出数据:@H_403_2@
导出后检查数据的记录数是否正确@H_403_2@
二、从txt导入数据到oracle
@H_403_2@
sqlldr是通过一个control文件设定后,从文本导入数据
@H_403_2@
建立一张测试表@H_403_2@
导入数据分成四种模式,可以根据需求选择:
@H_403_2@
APPEND // 原先的表有数据 就加在后面
@H_403_2@
INSERT // 装载空表 如果原先的表有数据 sqlloader会停止 默认值
@H_403_2@
REPLACE // 原先的表有数据 原先的数据会全部删除
@H_403_2@
TRUNCATE // 指定的内容和replace的相同 会用truncate语句删除现存数据
@H_403_2@
执行导入操作@H_403_2@
执行导入后验证数据@H_403_2@
导入成功
@H_403_2@
再执行一次导入操作,由于设置为追加:@H_403_2@
记录翻倍
@H_403_2@
sqlldr还有很多参数供选择,比如log、bad这些,查看帮助即可。@H_403_2@
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.
总结
@H_403_2@以上就是本文关于oracle数据与文本导入导出源码示例的全部内容,感兴趣的朋友可以参阅:、、数据库导入导出命令解析等,如有不足之处,欢迎留言指正,希望对大家有所帮助。感谢大家对编程之家网站的支持。@H_403_2@