Oracle
將平面文件中的數據載入到 oracle 表中
我創建了一個新數據庫,然後創建了一個表“使用者”。現在,我正在嘗試從名為“users.tbl”的平面文件中將數據載入到該表中,該文件具有以下格式的一些記錄:
1|john|email@email.email|active
我為此使用 SQL Developer,我嘗試了以下命令。
load data infile `"C:\path" insert into table users fields terminated by "|" lines terminated by "\r\n";
但是數據沒有載入,也沒有顯示錯誤。你明白為什麼它不工作了嗎?或者如何將平面文件中的數據載入到 Oracle 表中?
根據您的問題,您在平面文件中有數據,並且您想要訪問它或可以載入到另一個表。基本上你在談論外部表。你想了解更多。這是 Oracle 文件連結:外部表概念。
這是我如何將您的數據載入到我的外部表中並從中創建另一個表的範例。
[oracle@testsrv1 Desktop]$ cat user.tbl 1|john|email@email.com|active [oracle@testsrv1 Desktop]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 3 06:45:26 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SQL> create user user1 identified by user1; User created. SQL> create directory user_dir as '/home/oracle/Desktop'; Directory created. SQL> grant resource, connect to user1; Grant succeeded. SQL> grant read, write on directory user_dir to user1; Grant succeeded. SQL> conn user1/user1 Connected. SQL> create table user_load(user_id number, name varchar2(20), email varchar2(50), status varchar2(10)) organization external (default directory user_dir access parameters (fields terminated by '|') location('user.tbl') ); Table created. SQL> select * from user_load; USER_ID NAME EMAIL STATUS ---------- ---------- ------------------- ---------- 1 john email@email.com active SQL> create table final as select * from user_load; Table created SQL> select * from final; USER_ID NAME EMAIL STATUS ---------- ---------- ------------------- ---------- 1 john email@email.com active