Sponsored Content
Full Discussion: Doing a SQL rollup in unix
Top Forums Programming Doing a SQL rollup in unix Post 302646299 by bakunin on Friday 25th of May 2012 01:40:27 AM
Old 05-25-2012
The following is my take on it, using only shell builtins. I had to trim the first few digits of "tim" to use integer arithmetics (otherwise there would be overruns), you might want to find a more "long-term solution" for this. After all, the script is still a quick hack.

After the sorting and parsing it comes down to a simple group change with "$obj" as the group identifier.

Code:
#!/bin/ksh

print_summary ()
{

typeset obj="$1"
typeset -i elasum="$2"
typeset -i timsum="$3"

print - "Summary Object: $obj"
print - " - Sum ela: $elasum"
print - " - Sum tim: $timsum"

return 0
}



# main ()
typeset    obj=""
typeset    ela=0
typeset    time=0
typeset    lastobj=""
typeset -i elasum=0
typeset -i timsum=0
typeset    infile="/home/bakunin/tmp/oralog/input"

IFS=' '
grep '^WAIT' $infile |\
sort -k 12.6 |\
while read x x x x x x x ela x x x obj time x ; do
     obj="${obj#obj#=}"                     # "cook" the input
     time="${time#tim=5692604}"
     # print obj=$obj ela=$ela tim=$tim     # just for testing
                                            # simple group change
     if [ "$obj" != "$lastobj" ] ; then
          if [ -n "$lastobj" ] ; then
               print_summary "$obj" $elasum $timsum
               elasum=0
               timsum=0
          fi
          lastobj="$obj"
     fi

     (( elasum += ela ))
     (( timsum += time ))
done

print_summary "$obj" $elasum $timsum        # print last group

exit 0

I hope this helps.

bakunin

Last edited by bakunin; 05-25-2012 at 03:01 AM..
 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

unix variables from sql / pl/sql

How do I dynamically assign the below output to unix shell variables so I can build a menu in a shell script? Example: var1 = 1 var2= SYSTEM var3 = 2 var4= UNDOTBS1 and so on, then in the shell script I can use the variables to build a menu. set serveroutput on declare... (2 Replies)
Discussion started by: djehres
2 Replies

2. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

3. Shell Programming and Scripting

How to use sql data file in unix csv file as input to an sql query from shell

Hi , I used the below script to get the sql data into csv file using unix scripting. I m getting the output into an output file but the output file is not displayed in a separe columns . #!/bin/ksh export FILE_PATH=/maav/home/xyz/abc/ rm $FILE_PATH/sample.csv sqlplus -s... (2 Replies)
Discussion started by: Nareshp
2 Replies

4. Shell Programming and Scripting

rollup and concat fields in a group

Hello, I have a file with two fields in the following format.. NewYork|Rob Boston|Mellisa NewYork|Kevin Boston|John Chicago|Mike Boston|Tom My output should be: NewYork|Rob,Kevin Boston|Mellisa,John,Tom Chicago|Mike Basically I need to rollup on column A and stringconcat column... (5 Replies)
Discussion started by: bperl
5 Replies

5. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies
DBIx::Class::Storage::DBI::Oracle::WhereJoins(3)	User Contributed Perl Documentation	  DBIx::Class::Storage::DBI::Oracle::WhereJoins(3)

NAME
DBIx::Class::Storage::DBI::Oracle::WhereJoins - Oracle joins in WHERE syntax support (instead of ANSI). PURPOSE
This module is used with Oracle < 9.0 due to lack of support for standard ANSI join syntax. SYNOPSIS
DBIx::Class should automagically detect Oracle and use this module with no work from you. DESCRIPTION
This class implements Oracle's WhereJoin support. Instead of: SELECT x FROM y JOIN z ON y.id = z.id It will write: SELECT x FROM y, z WHERE y.id = z.id It should properly support left joins, and right joins. Full outer joins are not possible due to the fact that Oracle requires the entire query be written to union the results of a left and right join, and by the time this module is called to create the where query and table definition part of the SQL query, it's already too late. METHODS
See DBIx::Class::SQLMaker::OracleJoins for implementation details. BUGS
Does not support full outer joins. Probably lots more. SEE ALSO
DBIx::Class::SQLMaker DBIx::Class::SQLMaker::OracleJoins DBIx::Class::Storage::DBI::Oracle::Generic DBIx::Class AUTHOR
Justin Wheeler "<jwheeler@datademons.com>" CONTRIBUTORS
David Jack Olrik "<djo@cpan.org>" LICENSE
This module is licensed under the same terms as Perl itself. perl v5.18.2 2013-07-12 DBIx::Class::Storage::DBI::Oracle::WhereJoins(3)
All times are GMT -4. The time now is 02:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy