Can't load external file from unix into Oracle DB


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't load external file from unix into Oracle DB
# 8  
Old 11-25-2009
Quote:
Originally Posted by Tuut-Tuut
... that loading directly with sql+ isn't possible ...
That's an incorrect statement. It's very much possible.
The shell script shown here loads data via sqlplus only.

Code:
$  
$ # display contents of input data file
$ cat /tmp/input.csv                   
a,ab,abc                               
b,bc,bcd                               
c,cd,cde                               
d,de,def                               
$                                      
$ # display contents of the shell script
$ cat -n load_xtern.sh                  
     1  #!/bin/bash                     
     2                                  
     3  sqlplus -s /nolog <<EOF         
     4  connect test/test               
     5  -- create directory if not created already
     6  create or replace directory data_dir as '/tmp';
     7  -- create external table                       
     8  create table t_xtern (                         
     9    c1  varchar2(1),                             
    10    c2  varchar2(2),                             
    11    c3  varchar2(3)                              
    12  )                                              
    13  organization external                          
    14    ( default directory data_dir                 
    15      access parameters                          
    16      ( records delimited by newline             
    17        fields terminated by ','                 
    18      )
    19    location ('input.csv')
    20  );
    21  -- load into main table using external table; it's
    22  -- assumed that main table :
    23  -- t_main (x varchar2(1), y varchar2(2), z varchar2(3))
    24  -- exists at this point
    25  insert into t_main (x, y, z)
    26  select c1, c2, c3 from t_xtern;
    27  commit;
    28  exit
    29  EOF
    30
$
$ # now run the shell script
$ . load_xtern.sh

Directory created.


Table created.


4 rows created.


Commit complete.

$
$ # check the data loaded into the main table - t_main
$ echo "select * from t_main;" | sqlplus -s test/test

X Y  Z
- -- ---
a ab abc
b bc bcd
c cd cde
d de def

$
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to load XML file to Oracle table

Experts. I have created a oracle table as below. create table xml_tab ( File_No number , File_content Varchar2(2000), file_type xmltype ); Daily we are receiving many XML files as below. here is our sample xml file. File1 : (7 Replies)
Discussion started by: vasuvv
7 Replies

2. Shell Programming and Scripting

Script to load daily average I/O stats from a .ksh file into Oracle db

Hi can anyone help me with a script to load output of the .ksh file into an Oracle database. I have attached sample output of the information that i need to load to the database (2 Replies)
Discussion started by: LucyYani
2 Replies

3. Shell Programming and Scripting

why do we need UNIX shell script to load data into Oracle database

Hello everyone, I am new to shell scripting/ loading data into a database. I want to load data into Oracle database using SQL loader. Can some one please explain why do we need unix shell script to load the data into the database? Also can someone please explain what has to be in that script?... (5 Replies)
Discussion started by: new_prog
5 Replies

4. Shell Programming and Scripting

load file to sharepoint using unix

I have a requirement to upload a file to the MS sharepoint site using unix or any other programming language. Does sharepoint support ftp? I heard it doesn't ...is it true...if yes is it different from what regular ftp we use....is there any other programming way out to upload the file to... (1 Reply)
Discussion started by: RubinPat
1 Replies

5. Shell Programming and Scripting

Load data from a flat file to oracle.

I have a flat file with records like Header 123 James Williams Finance2000 124 Pete Pete HR 1500 125 PatrickHeather Engg 3000 Footer The structure is: Eno:4 characters Name:8 characters Surname : 9 characters Dept:7 characters Sal:4characters These are sample... (1 Reply)
Discussion started by: Shivdatta
1 Replies

6. Shell Programming and Scripting

load a data from text file into a oracle table

Hi all, I have a data like, 0,R001,2,D this wants to be loaded into a oracle database table. Pl let me know how this has to be done. Thanks in advance (2 Replies)
Discussion started by: raji35
2 Replies

7. Shell Programming and Scripting

How to read a dynamically changing file and load into Oracle?

I have a tab delimited file which has 27 character fields. The file needs to be loaded into an Oracle table. But the challenge is that everytime the file comes it may or may not have values in all 27 fields. Column Definition of the 27 fields: TYPE: Char (1) NAME: Char (30) CUSTOM_VAL: Char... (8 Replies)
Discussion started by: madhunk
8 Replies

8. Programming

How can i load or insert a table in oracle from c language thru unix environment

I'm having a oracle server and i'm having a table in that. I'm having a linux server which is in network with the oracle server. I need to write a c program in linux env when on execution loads the table with the text file given as input. Please explain me the flow of process in that and also... (6 Replies)
Discussion started by: rramprasad
6 Replies

9. UNIX for Advanced & Expert Users

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (4 Replies)
Discussion started by: handynas
4 Replies

10. UNIX for Dummies Questions & Answers

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (5 Replies)
Discussion started by: handynas
5 Replies
Login or Register to Ask a Question