using Oracle within an awk script 
Author Message
 using Oracle within an awk script

Hi everybody.

I would perform some simple statements (select)  in a awk script
(AIX 4.3.10) connecting to a DB Oracle  ( 7.3.3 ).

So I wrote the following ( quite rough ! )  function,  
using system() statement :
===========================================
function execute_sql ( query, param )
{
    system ("echo " query " > sel.sql" ) ;

    if ( param != "" )
    {
        system ("echo \"where\"  >> sel.sql" ) ;
        system ("echo " param "  >> sel.sql" ) ;
    }

    system ("echo  \";\nquit\" >> sel.sql" ) ;

Quote:
}

===========================================
Now, my questions are :

1) Which is a better way to do the same ?

2) Even using my way, how it is possible
     to get the result of the query itself ?

      For example in a call like the following :
      execute_sql ( "select u_type from users", "user_id=1234 " )
      I would pass back the result of the query to the script.

Thanks in advance for your help.
Kinds regards,
Paolo



Sat, 21 Sep 2002 03:00:00 GMT  
 using Oracle within an awk script

% I would perform some simple statements (select)  in a awk script
% (AIX 4.3.10) connecting to a DB Oracle  ( 7.3.3 ).

awk falls down a bit when you do things like this.

% function execute_sql ( query, param )
% {
%     system ("echo " query " > sel.sql" ) ;

(bleah!) Please use the print statement of awk:
      cmdfile = "sel.sql"
      print query > cmdfile

%     if ( param != "" )
%     {
%         system ("echo \"where\"  >> sel.sql" ) ;
%         system ("echo " param "  >> sel.sql" ) ;
%     }

      if (param != "") print "where", param ";" >> cmdfile
      close(cmdfile)


To get the output from sqlplus:

      while ((cmd | getline) > 0) {
         # fiddle with the output
      }
      close(cmd)

% 1) Which is a better way to do the same ?

If you need to process the results, you could do it as above. sqlplus
has a lot of stuff to allow you to format your result sets. You should
at least set the linesize so each row gets returned on a separate line.

If you don't mined the results going to the screen, you can feed the
output of the print statement straignt into sqlplus:
  cmd = "sqlplus user/password"
  print query | cmd
  print morequery | cmd
  close(cmd)

--

Patrick TJ McPhee
East York  Canada



Sun, 22 Sep 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Access to Script Name Within Awk Script

2. Running a TK script using wish80.exe within a tcl script

3. Replacing a string from an input file within awk script

4. trying to call awk from within a shell script

5. Run awk from within sed script?

6. shell commands within awk script

7. Simple awk command within a perl script

8. awk within ksh script

9. Running Awk scripts from within VB

10. Shell variable within an awk script

11. How to specify input file within awk script?

12. Using Cat within AWK

 

 
Powered by phpBB® Forum Software