How to redirect the selected table to file in perl?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to redirect the selected table to file in perl?
# 1  
Old 02-08-2011
How to redirect the selected table to file in perl?

Hi,

I am connecting to oracle database using perl. I want to redirect the selected output to file. I am not able to do that in Oracle.
Here is the code.
Code:
SQL>    SELECT name INTO OUTFILE "/orahome/test.txt" FROM dummy;
                                         *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

I have 2 questions.
a) How to execute and redirect the query simultaneosly?

For example: Select name from table and redirect to test.csv?

b) How to redirect the results or the table data to a csv file in perl?

I am new to Oracle so finding bit difficulty,

Help is very much appreciated.

Regards
# 2  
Old 02-08-2011
You could try something like this:

Code:
perl -MDBI -Mstrict -le'
  
  my $csv = "my.csv";
  my $dsn = "<your_tns>";
  my $usr = "<user>";
  my $passwd = "";
  my ($dbh, $sth, $fh, $town, $tname);
  
  open $fh, ">", $csv or die "open: $!\n";

  $dbh = DBI->connect("dbi:Oracle:$dsn", $usr,
                    $passwd, {RaiseError => 1, PrintError =>0});

  $sth = $dbh->prepare("select owner, table_name from all_tables");
  $sth->execute();
  print $fh "$town, $tname" while (($town, $tname) = $sth->fetchrow());
  
  $sth->finish();
  $dbh->disconnect();
  
  close $fh or warn "close: $!\n";

  '

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input data of a file from perl into HTML table

Hi , I need an help in perl scripting. I have an perl script written and i have an for loop in that ,where as it writes some data to a file and it has details like below. cat out.txt This is the first line this is the second line. .....Now, this file needs to be send in mail in HTML... (2 Replies)
Discussion started by: scott_cog
2 Replies

2. Red Hat

This doesn't look like a partition table Probably you selected the wrong device.

Hi, I need to mount the device from this device # fdisk -l . . . Disk /dev/sdas: 2000.4 GB, 2000365289472 bytes 255 heads, 63 sectors/track, 243197 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size... (0 Replies)
Discussion started by: justbow
0 Replies

3. Shell Programming and Scripting

Perl: Writing table values to a file

I have a file like this, 1,a,saurav 2,b,rout I want to show this file in a perl cgi page table and want to add a column which will contain a text box. There I will give some manual input, which will be written to the existing file(or a new file) in below format. 1|a|saurav|bangalore... (2 Replies)
Discussion started by: sauravrout
2 Replies

4. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

5. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

6. Shell Programming and Scripting

Sum value from selected lines script (awk,perl)

Hello. I face this (2 side) problem. Some lines with this structure. ........... 12345678 4 12345989 13 12346356 205 12346644 74 12346819 22 ......... The first field (timestamp) is growing (or at least equal). 1)Sum the second fields if the first_field/500 are... (8 Replies)
Discussion started by: paolfili
8 Replies

7. Shell Programming and Scripting

retrieve what the currently selected item is in a dropdown select list using perl tk

I have a dropdown menu built in perl tk (I am using active state perl). I want to select a value from the dropdown menu and I want to be able to perform some other actions depending upon what value is selected. I have all the graphical part made but I dont know how to get the selected value. Any... (0 Replies)
Discussion started by: lassimanji
0 Replies

8. Shell Programming and Scripting

perl redirect output to file ..not working

here is simple perl script i wanted for my net connection ... just to check if default gateway is pingable or not if not write in log file but problem is that i can not write in file i can print on STDOUT but not in file ...why so ?? same thing was there when i was tying to write on sockets... (7 Replies)
Discussion started by: zedex
7 Replies

9. UNIX for Dummies Questions & Answers

extracting selected few lines through perl

How can I extract few lines(like 10 to 15, top 10 and last 10) from a file using perl. I do it with sed, head and tail in unix scripting. I am new to perl. Appreciate your help. (2 Replies)
Discussion started by: paruthiveeran
2 Replies

10. UNIX for Dummies Questions & Answers

Perl - converting selected characters to upper/lower case

Using STDIN, how can I use perl to take an input string, with all lower case letters in the first five characters, and convert them to uppercase... then take all uppercase letters in the second five characters and convert them to lowercase. Example: MichaelSmith to michaELSMIth Thank you! (2 Replies)
Discussion started by: doubleminus
2 Replies
Login or Register to Ask a Question