LOAD DATA INFILE 在 Oracle 中等效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8953110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LOAD DATA INFILE equivalent in Oracle
提问by Mikayil Abdullayev
I just was wodering if there's an equivalent to MySQL LOAD DATA INFILE statemnent in Oracle? I need it because I want to read from a huge textfile into a database table.
我只是想知道 Oracle 中是否有等效于 MySQL LOAD DATA INFILE 的语句?我需要它,因为我想从一个巨大的文本文件中读取到一个数据库表中。
采纳答案by BigMike
Oracle gives the SQLLoadercommandline utility. But it relies on a proper formatting of the data file.
Oracle 提供了SQLLoader命令行实用程序。但它依赖于数据文件的正确格式。
You can try to look at Oracle External Tables(e.g. you can link a csv file as an external table and see it as a table within Oracle).
您可以尝试查看Oracle 外部表(例如,您可以将 csv 文件链接为外部表,并将其视为 Oracle 中的表)。
Both solutions have pros and cons, but the big cons is that they still rely on data input format (so if you have a file ready for mysql, you may need to tweak it a bit).
这两种解决方案各有利弊,但最大的缺点是它们仍然依赖于数据输入格式(所以如果你有一个准备好用于 mysql 的文件,你可能需要稍微调整一下)。
回答by Jorge T
Example on windows 10 and Oracle 12c
Windows 10 和 Oracle 12c 上的示例
if you have a text file with records of each table delimited by comma, you can do this:
如果你有一个文本文件,每个表的记录用逗号分隔,你可以这样做:
Create a control file for each table, called table_name.ctl (C:\Users\user\Desktop\directory\table_name.ctl)
为每个表创建一个控制文件,名为 table_name.ctl (C:\Users\user\Desktop\directory\table_name.ctl)
load data
infile 'C:\Users\user\Desktop\directory\table_name.txt'
append
into table table_name
fields terminated by ","
(id, field2,field3)
After, In windows you should open Cmd and load data in each table, and then load data remotely for example in a aws server.
之后,在 Windows 中,您应该打开 Cmd 并在每个表中加载数据,然后远程加载数据,例如在 aws 服务器中。
sqlldr userid=USER@AWS_PDB1/password
control='C:\Users\user\Desktop\directory\table_name.ctl' log='C:\Users\user\Desktop\directory\table_name.log' direct=true
or
或者
sqlldr control='C:\Users\user\Desktop\directory\table_name.ctl' log='C:\Users\user\Desktop\directory\table_name.log' direct=true
and then ask them the user and password
If you have the following error:“The program can't start because oranfsodm12.dll is missing from your computer. Try reinstalling the program to fix this problem.”
如果您遇到以下错误:“程序无法启动,因为您的计算机缺少 oranfsodm12.dll。尝试重新安装程序以解决此问题。”
it is because SQL * Loader is disabled and can not be used in the console windows, this is solved enabling the following steps (as http://www.dallasmarks.com/installing-two-oracle-12c-clients-on-one-server/):
这是因为 SQL * Loader 被禁用并且无法在控制台窗口中使用,这是通过启用以下步骤解决的(如http://www.dallasmarks.com/installing-two-oracle-12c-clients-on-one -服务器/):
Should go to the folder C:\oracle\client\user\product\12.1.0\client_1\BIN
Make a copy of oraodm12.dll file, calling the new file oranfsodm12.dll, and paste it in the same BIN folder.
Run the command again from cmd.
应该转到文件夹 C:\oracle\client\user\product\12.1.0\client_1\BIN
复制oraodm12.dll文件,调用新文件oranfsodm12.dll,粘贴到同一个BIN文件夹中。
从 cmd 再次运行该命令。