unix file to oracle table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unix file to oracle table
# 1  
Old 06-14-2008
unix file to oracle table

Hi ,
Can anyone help me regarding loading a unix file data to oracle database table using shell scripts?


I wanted to grep only this data from a spool file
sql_test.txt
99
00:00:00:01

but if I use grep I am getting format
sql_test.txt
99 rows selected.
Elapsed: 00:00:00.01
convert the elapsed time to seconds and then

I want to load
sql_test.txt,99,00:00:00:01(converted to second like .0001 )
to a oracle table with columns
Query
rows
Elapsed
# 2  
Old 06-14-2008
If your input file contains exactly this:

Code:
sql_test.txt
99 rows selected.
Elapsed: 00:00:00.01

You can obtain the insert statement by executing:
Code:
awk '
   /rows selected/ { $0=$1 }
   /Elapsed/       { split($2, t, ":"); $0=3600*t[1]+60*t[2]+t[3] }
                   { out=out sprintf("%s%s", NR==1?"":",", "\047"$0"\047") }
   END             { print("insert into MY_TABLE values ("out");") }
' input_file.txt

The generated output is:
Code:
insert into MY_TABLE values ('sql_test.txt','99','0.01');

# 3  
Old 06-14-2008
It worked

Thank you So much it worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help Needed: UNIX shell variables to store Oracle table records

Hello Folks, I'm working on a requirement to automate the process of generating report(csv file) using metadata info stored in an Oracle table and E-mail it to respective people. Meta data table: Report_ID,Report_SUB_ID,Report_DB,Report_SQL,Report_to_email_Id 1,1,DEV,'select * From... (2 Replies)
Discussion started by: venkat_reddy
2 Replies

2. UNIX and Linux Applications

UNIX spool command not extracting complete record from the Oracle table

Hello All, I'm trying to spool an oracle table data into a csv file on unix server but the complete record is not being extracted. The record is almost 1000 characters but only 100 characters are being extracted and rest of the data getting truncated. I'm setting below options : SET... (4 Replies)
Discussion started by: venkat_reddy
4 Replies

3. UNIX and Linux Applications

Help in copying table structure to another table with constraints in Oracle

hi, i need to copy one table with data into another table, right now am using create table table1 as select * from table2 i want the constraints of table1 to be copied to table2 also , can anyone give me some solution to copy the constraints also, now am using oracle 10.2.0.3.0... (1 Reply)
Discussion started by: senkerth
1 Replies

4. Shell Programming and Scripting

How to lock Oracle table through UNIX?

Hi frndz, Can anyone provide me some input or pseudo code for my req as mentioned below... I am loading 2 files through unix script into oracle table...as i am doing some updates also i am getting an error where both files try to update the table simultaneously and my script fails.. so i... (3 Replies)
Discussion started by: gnnsprapa
3 Replies

5. Shell Programming and Scripting

Delete oracle table from UNIX script

Hi, Is it possible to delete oracle table datas using a UNIX script/Shell script? how can we do this?? I have oracle Database and i have to delete millions of record everyday.. adn it is taking hours togather to execute this. Will the delete query triggered from UNIX be faster can we expect any... (1 Reply)
Discussion started by: Codesearcher
1 Replies

6. Shell Programming and Scripting

Insert into Oracle table thru UNIX - linux 2.6.9-89

Hi, I am trying to insert a record into a table (say dips_tbl) which resides in Oracle DB through a ksh script. I want to insert records into few of the table columns-not all. I'll give an e.g. for the date column "CREATE_DATE". For that I first execute SQL1="SELECT SYSDATE FROM DUAL" ... (1 Reply)
Discussion started by: dips_ag
1 Replies

7. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time then Go to sleep mode and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

8. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time (Go to sleep mode) and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

9. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies

10. 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
Login or Register to Ask a Question