Sponsored Content
Top Forums Shell Programming and Scripting Insert value to ORACLE table from sqlldr log Post 302288730 by aimy on Tuesday 17th of February 2009 11:33:24 PM
Old 02-18-2009
Power

Quote:
Originally Posted by bakunin
/Moderative Mode ON

First of all, you shouldn't bump up questions, because it is against the rules.

Second: please notice that this is not a help desk. If you want informed, precise answers to be given within a certain timeframe please consider hiring an UNIX expert.

Third: please bear in mind, that all people answering here are VOLUNTEERS. They might be (in fact they are) most times interested in helping you or someone else but they are not obligated to do so. If they do not feel like it (and, frankly, exhibiting a demanding attitude like you did makes them not feeling like it more likely) they do not have to answer at all.

Fourth: all these boards are about is helping one to help himself. Right now you have shown more effort in getting us to work faster than in solving your problems yourself. Take this as an opportunity to think over (and perhaps rearrange) your priorities.

/Moderative Mode OFF
, User Mode ON

There is a simple answer to your problem: probably it could be solved with a finite effort and a little sed-scripting.

Longer answer: the real problem lies perhaps in the analysis of the problem and in formulating a solution which is general and reliable enough to let it run unsupervised. For this there are simply not enough data.

Some questions you will have to answer: you have provided a file with exactly one error. How would a file look like when there are two (any arbitrary number of) errors? How does the file look like when there are no errors at all? How will the file look like when there are different types of errors (say, the load stops midways because of some error - file error, disk full, what else)?

A stable and reliable script would be able to parse all these types of output (in fact it should be able to cope with every possible output) therefor you have to take all these different (?) output formats into account.

So please give more details and maybe we can work out a script that does exactly that or try to write one yourself. Provided that the problems mentioned above can be overcome here is a way to isolate your needed values:

You search for a specific value (for the sake of the example we will use start_time) and you know how the line looks like which contains this value:

Code:
.... any text ....
....
Run began on Sun Feb 08 23:37:02 2009
... some more text ....

You can search for this line easily with sed. Now replace the fixed text part "Run began on" with the variable name you want to assign it to to form a declaration:

Code:
sed -n 's/^Run began on/start_time \=/p'

And you will notice that from your logfile you will get out a single declaration reading:

Code:
start_time = Sun Feb 08 23:37:02 2009

This declaration you could directly use to initialize some variables in your script (source the file written this way in).

I hope this helps.

bakunin
Thanks for your response and please do forgive me about my bad behavior.. Smilie

It's just that I feel my question is not that complicated but yet not one seems to answer.. Smilie

While waiting for the solution, I take my own iniative to study a bit about awk utility.

So, this is what I got:

Code:
table_name = awk '/Table.+[:]/ {print substr($2,10)}' testfile.log
row_insert = awk '/Rows successfully loaded./ {print $1}' testfile.log
row_reject = awk '/not loaded due to data errors./ {print $1}' testfile.log
v_ErrorText = awk '/^ORA-/ {print}' testfile.log
start_time = awk '/Run began on/ {print $5, $6, $7, $8}' testfile.log
sysdate = '/Run ended on/ {print $5, $6, $7, $8}' testfile.log
elapsed_time = awk '/Elapsed/ {print substr($4,1,2)*3600 + substr($4,4,2)*60 + substr($4,7)}' testfile.log

sqlplus -s crispadm/admcrisp <<EOF
set autocommit on;
set echo on;
set serveroutput on;

insert into PROCEDURE_TRACKING_LOG
(procedure_name, table_name, rows_inserted, rows_updated, rows_deleted, rows_inserted_of_deletion, 
rows_inserted_after_deletion, rows_rejected, start_time, end_time, elapse_time, remarks, subject_area)
values
('TEST',replace($table_name,':'),$row_insert,NULL,NULL,NULL,
NULL,$row_reject,$start_time,$sysdate,round($elapsed_time),$v_ErrorText,'NETWORK INVENTORY');

EOF

All the awk command works fine:
Code:
$ awk '/Table.+[:]/ {print substr($2,10)}' testfile.log
BILLED_RECURR_CHARGES:

$ awk '/Rows successfully loaded./ {print $1}' testfile.log
1722967

$ awk '/not loaded due to data errors./ {print $1}' testfile.log
1

$ awk '/^ORA-/ {print}' testfile.log
ORA-01400: cannot insert NULL into ("CRISPADM"."BILLED_RECURR_CHARGES"."SEF_CODE")

$ awk '/Run began on/ {print $5, $6, $7, $8}' testfile.log
Feb 08 23:37:02 2009

$ awk '/Run ended on/ {print $5, $6, $7, $8}' testfile.log
Feb 08 23:42:19 2009

$ awk '/Elapsed/ {print substr($4,1,2)*3600 + substr($4,4,2)*60 + substr($4,7)}' testfile.log
317.27

So, where i do went wrong in the script to set all that awk commands as a variable?

Thank you.
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 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

Insert script result into Oracle Table

Hi All, I want to insert STAT and ENDTIME values for each job in joblist into TBL_DAILY_STATUS table. Eg: insert into tbl_daily_status values(STAT,ENDTIME); Please help me on this. #!/bin/ksh joblist="com_abc_job com_abc_dot_job com_abc_seq com_abc_det" for i in $joblist do... (8 Replies)
Discussion started by: vichuelaa
8 Replies

8. 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

9. Shell Programming and Scripting

Script to create the SQLLDR control file from Oracle table.

I need to create the shell script load the few 100 table using the SQLLDR. Need to generate the control file for each table using oracle table. table has "table names" and "column names" using this need create the control file. example table rows below table_nme column_nme DEPT ... (2 Replies)
Discussion started by: pimmit22043
2 Replies
All times are GMT -4. The time now is 03:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy