|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: code to load data from text to table ? [message #568697 is a reply to message #568696] |
Tue, 16 October 2012 00:19   |
 |
Littlefoot
Messages: 17255 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
OK then, a SQL*Loader solution.
Does the DEPT.TXT file exist?
M:\>dir dept.txt
Volume in drive M is file sharing 1
Volume Serial Number is 98A9-A7AE
Directory of M:\
16.10.2012. 07:07 106 dept.txt
1 File(s) 106 bytes
0 Dir(s) 426.070.016 bytes free
A control file - can't be simpler:
load data
INFILE 'dept.txt'
into table dept2
replace
fields terminated by '|'
(deptno,
dname,
loc
)
Let's create an empty DEPT2 table:
SQL> show user
USER is "MIKE"
SQL> create table dept2 as select * from dept where 1 = 2;
Table created.
SQL>
Loading session and the result:
SQL> $sqlldr mike/lion@ora10 control=test6.ctl log=test6.log
SQL*Loader: Release 11.2.0.2.0 - Production on Uto Lis 16 07:13:40 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 3
Commit point reached - logical record count 4
SQL> select * from dept2;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL>
The above solution works fine as SQL*Loader allows you to load files which are stored on your own PC, while the database can be a local one (as you have it) or somewhere on the network.
An external table solution Michel suggested isn't that flexible as it requires that the input file is located on the database server, which can be tricky if you don't have access to the server - then you have to ask someone (a DBA) to create a directory (Oracle object which points to a "real" directory on database server's file system) and grant you privileges to use it from Oracle tools. However, DBA doesn't have to be a nice person and won't let you put files onto that server so you'd have to ask him/her to do that for you every time.
However, as you are a DBA of your own database, I'd suggest you to read the documentation and find a way to do the same job, but this time using the external tables feature.
|
|
|
|
|
|
| Re: code to load data from text to table ? [message #568727 is a reply to message #568705] |
Tue, 16 October 2012 02:13  |
 |
Littlefoot
Messages: 17255 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
|
Right! But this case is a special case as he is using a database installed on his own PC so ... no problem in doing anything he wants. Some day, in the future, that might not be the case. I admit, my thoughts may be irrelevant.
|
|
|
|