I have tried to use system command but still it errored. Can you show how to call sqlplus from awk?
What i want to achieve is to read specific postions in the line from input file (because those position are the primary key value for the query written in Procdure); invoke sqlplus call procedure and pass the parameters just read using substring, get the value from procedure then replace a specific position in the line which is just read by the value provided by sqlplus procedure.
Bottleneck is that I am unable to invoke sqlplus from awk. Any more ideas?
As far as possible try to modularize your approach as there are so many advantages over something that achieves in a single shot
ease of maintenance
re usability
easy to debug
no need to test the entire application if its properly modularized
and of course, nobody would curse you if somebody else has to maintain your code
for your problem you could modularize it something like
( what I post is just an example )
fetching data from db into a file
processing the data from the file
redirecting output
now the problem space is broken down easily and you could easily challenge any of the module if there is a problem.
I have burnt my fingers many times since I don't have the habit of modularizing the code and I end up writing the same code again, do the same testing again, same debugging again.
I have to admit - its a shame !
Waste of time for which I had already wasted.
I tried running your version of the script, the sql file is getting proper parameters and sqlplus is getting invoked but I am getting some wired error on the shell.
The above error is getting displayed the number of times it finds RT3 record and trying to call sqlplus.
I have checked the procedure in oracle and the output is expected when I copy and paste the exec command which is written in the sqlfile.
I have absolutely no idea why the error is being provided.
The sqlplus is in the PATH and I tired invoking sqlplus directly from the shell and it is working fine.
I tried using the command
sql_val=system(sql_cmde);
close(sql_cmde);
But then the shel script just freezes, but somehow
It is working fine now, I changed the printf from printf("exec abc_ert(%s, %s, %s, %s, %s, %s);\n",
$tr , $ap, $ver, $irver, $recdate, $logdate) > sql_file;
to
printf("set serveroutput on format wrap;\nexec abc_ert(%s, %s, %s, %s, %s, %s);\n exit;\n", $tr , $ap, $ver, $irver, $recdate, $logdate) > sql_file;
The problem was exit statement was missing!!!
Amazing solution to very complex problem we encountered. Thanks to all.
I have another problem with this script which is doing what it is suppose to do but now the problem is with AWK which is unable to read input line more than 3000 bytes.
The error I am getting from AWK is
Is this a restriction in awk that it cannot read input line which is greater than 3000 bytes?
In the logic of your awk program, there is no need to read the output of sqlplus command as you print it only, hust execute the command.
In that case, the awk restriction doesn't matter
Aigles,
The problem is not writing or reading the input line which matches the pattern criteria. Some of the lines in the file is greater than 3000 bytes (characters). AWK is unable to read these lines and provides error before it could even read the line to check for the pattern.
Is it possbile to set max of the input line i.e $0 ?
Aigles,
I want the content of new file to be same as original file. What I want is to replace the text (for the line having RT3 content) at position at 2651 by the value being passed by Oracle Stored procedure. If the line which is not RT3 is found then awk has to re-write the line as it is to new file.
The problem is that this line which is not RT3 some times has more than 3000 bytes of data and awk is unable to parse it.