oracle reports from unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting oracle reports from unix
# 1  
Old 05-30-2009
oracle reports from unix

i have sql script (ex:a.sql) that generates 10 csv files
ex: a.csv
b.csv
c.csv .........
but donot want 10 separate csv files
i want a single csv files with 10 different tab that contains all data
is it possible from unix
Smilie
# 2  
Old 05-30-2009
In the script or command you do:
Code:
command > file.csv
secondcommand >> file.csv
thirdcommand >> file.csv

Then the first line will create a new file.csv file or else overwrite any existing file.csv, the second and third lines will append to the file.csv file.
# 3  
Old 05-30-2009
Quote:
Originally Posted by alokjyotibal
...
i want a single csv files with 10 different tab that contains all data
is it possible from unix
...
A csv file is a plain text file with no formatting. As such, it cannot have "tabs" (unless I am missing something here.)

In case you mean an Excel workbook with more than one worksheet (a "tab" being a "worksheet"), then you can use perl.

This perl program loops through each csv file in the current directory and prints the data to a worksheet in the workbook "alldata.xls" in the current directory. The name of the csv file is the name of the worksheet.

Code:
$ 
$ # display the contents of the csv files
$ cat a.csv
abc,123,def,12.34
xyz,456,pqr,99.87
def,389,rst,1234.56
$                  
$ cat b.csv        
abcdefghi,123456.789
bcdefghij,234567.890
$                   
$ cat c.csv
a,1,bcd,1.2,efg
b,2,cde,2.3,fgh
c,3,def,3.4,ghi
$              
$ # display the contents of the perl program
$                                           
$ cat createwsheets.pl                      
#!/usr/bin/perl -w                          
use Spreadsheet::WriteExcel;                

# create a new workbook
my $workbook = Spreadsheet::WriteExcel->new('alldata.xls');
# loop through csv files                                   
foreach $file (glob "*.csv") {                             
  print "Processing file    => $file\n";                   
  open (F, $file) or die "Can't open $file: $!";           
  @x = <F>;                                                
  close (F) or die "Can't close $file: $!";                
  ($worksheet = $file) =~ s/.csv//;                        
  print "Creating worksheet => $worksheet\n";              
  # create a new worksheet in the workbook                 
  $worksheet = $workbook->add_worksheet($worksheet);       
  $col = $row = 0;
  foreach $elem (@x) {
    @data = split/,/, $elem;
    foreach $cv (@data) {
      # print data in worksheet
      $worksheet->write($row, $col, $cv);
      $col++;
    }
    $row++;
    $col = 0;
  }
  print "-"x30,"\n";
}

$
$ # run the perl program
$
$ perl createwsheets.pl
Processing file    => a.csv
Creating worksheet => a
------------------------------
Processing file    => b.csv
Creating worksheet => b
------------------------------
Processing file    => c.csv
Creating worksheet => c
------------------------------
$
$ ls -1 *.csv *.xls
a.csv
alldata.xls
b.csv
c.csv
$
$

In fact, you can reduce some overhead by avoiding the creation of these csv files in the first place.

If you know the structure of your SQL script (which, I am assuming, contains a lot of "spool" commands if your database is Oracle), then you can:

(1) Loop through the SQL script, saving each SQL or PL/SQL "block" in an array or an equivalent data structure.
(2) Connect to Oracle via DBI.
(3) Loop through the array created in Step (1) and execute a "block" per iteration.
(4) Create a worksheet and print the results in it.
(5) Repeat Steps (3) and (4) for the entire array.
(6) Close the DBI connection.

Hope that helps,
tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX/Linux help in concatenation of multiple reports

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

2. Shell Programming and Scripting

Scheduling BO Webi Reports Through Unix Server

Hi, We have developed Some BO reports in Webi and our requirements is as follows 1)ETL File will be generated and sent to BO server through autosys and once BO server receives that ETL file then BO reports are scehduled on Event based and triggered automatically.(If any failure in report... (0 Replies)
Discussion started by: Sashanth_S
0 Replies

3. UNIX and Linux Applications

Installation of Oracle Reports 6i on Linux

Hi, We are planning for a report generation program in Linux.For that we are planning to use Oracle reports 6i on linux. Could anybody please confirm if the Oracle 6i reports are compatible on Linux (0 Replies)
Discussion started by: Pavan Pusuluri
0 Replies

4. UNIX for Dummies Questions & Answers

Where do barcode fonts go (Oracle reports)

I have been asked to upload a font file for barcodes (3of9.ttf) to a unix server so that users of Oracle Reports on Oracle 10g can pick up this font. Where should this file be placed? (0 Replies)
Discussion started by: Chantho
0 Replies

5. UNIX for Dummies Questions & Answers

unix for oracle

Hi unixers, :) Anyone have any links or online tutorials for Shell Scripting with respect to Oracle . Any example of script calling any Oracle procedure or function or passing parameters is highly appreciated. (6 Replies)
Discussion started by: ravi raj kumar
6 Replies

6. HP-UX

Restore of oracle 8i from hp unix 11.0 to HP unix 11i

Hi, We are planning to migrate oracle 8.1.7.2 (8i) currently installed on a host with HP unix 11.0 to a host with HP Unix 11i. The method we are adopting is backup and restore of all file systems. Could this be a problem, apart from linking libraries on the target system. Thanks for the... (1 Reply)
Discussion started by: amitb
1 Replies

7. HP-UX

Hp-ux 11.11 and Oracle reports

HI I am battling to find why oracle reports dont work from the Oracle applications and work from the Command line Finally, whern these reports error out in the Oracle apps, I see the error that the x server killed the process. Please let me know if any one has some chi-chi sheet on the os setup... (1 Reply)
Discussion started by: schilukuri
1 Replies
Login or Register to Ask a Question