Sponsored Content
Top Forums Shell Programming and Scripting Redirecting sql select query result to txt file Post 302208501 by dolphin123 on Tuesday 24th of June 2008 04:21:47 AM
Old 06-24-2008
Redirecting sql select query result to txt file

Hi Yogesh,
Lucky that i caught you online. Yeah i read about DBI and the WriteExcel module. But the server is not supporting these modules. It said..."Cannot locate DBI"..."Cannot locate Spreadsheet::WriteExcel"

I tried creating a simple text file to get the query output, but the data was just thrown into the text file. There was no format.

How should i include code in sql file (containg the select query) so that the output to the text file is formatted neately with tab.

Kindly help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

formatting the sql select result

Hi, I have about 12 columns and 15 rows to be retrived from sybase isql command through unix. But when i output the sql into a file and see it, the formatting is going for a toss. can someone please suggest how can i get the result correctly in the output file ? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies

2. Shell Programming and Scripting

how to convert the result of the select query to comma seperated data - urgent pls

how to convert the result of the select query to comma seperated data and put in a .csv file using korn shell. Pls help me as its very urgent. Thanks, Hema. (1 Reply)
Discussion started by: Hemamalini
1 Replies

3. Shell Programming and Scripting

Redirecting sql select query result to txt file

Hi , I just found you while surfing for the string 'Redirecting sql select query output from within a shell script to txt file/excel file' Could you find time sending me the code for the above question? It'll be great help for me. I have a perl file that calls the sql file... (1 Reply)
Discussion started by: dolphin123
1 Replies

4. Shell Programming and Scripting

In a csh script, can I set a variable to the result of an SQLPLUS select query?

Can someone tell me why I'm getting error when I try to run this? #!/bin/csh -f source ~/.cshrc # set SQLPLUS = ${ORACLE_HOME}/bin/sqlplus # set count=`$SQLPLUS -s ${DB_LOGIN} << END select count(1) from put_groups where group_name='PC' and description='EOD_EVENT' and serial_number=1;... (7 Replies)
Discussion started by: gregrobinsonhd
7 Replies

5. Shell Programming and Scripting

How to Format the result driven from a SQL Query

Hi All, I want to format the result driven from the query into neat format. For example pls find the below code, #! /bin/sh result=' sqlplus -s uname/passwrd@DBname select no,name,address,ph_no, passport_no,salary,designation from emp_table where salary>1000; exit EOF' ... (8 Replies)
Discussion started by: little_wonder
8 Replies

6. Shell Programming and Scripting

redirecting sql query output to a file

Hi, I am executing sql files in my unix shell script. Now i want to find whether its a success or a failure record and redirect the success or failure to the respective files. meaning. success records to success.log file failure record to failure.log file. As of now i am doing like... (1 Reply)
Discussion started by: sailaja_80
1 Replies

7. Shell Programming and Scripting

redirecting oracle sqlplus select query into file

So, I would like to run differen select queries on multiple databases.. I made a script wich I thought to be called something like.. ./script.sh sql_file_name out.log or to enter select statement in a command line.. (aix) and I did created some shell script wich is not working.. it... (6 Replies)
Discussion started by: bongo
6 Replies

8. UNIX for Advanced & Expert Users

Output the SQL Query result to a File

Hello Guys, This message is somewhat relates with last thread. But I need to re-write thing. I start over a little. I am stuck now and need your help. Here is my script- #! /bin/ksh export ORACLE_HOME=/opt/oracle/app/oracle/product/9.2 /opt/oracle/app/oracle/product/9.2/bin/sqlplus -s... (5 Replies)
Discussion started by: thepurple
5 Replies

9. Shell Programming and Scripting

How to store the sql query output into txt file?

Hi I want ot save SQL query result in one txt file. for that i have written one code line sqlplus -s $dbstring @/usr/local/bin/sched/nightly_Cronjob/exec_123.sql >> /usr/local/bin/sched/nightly_Cronjob/result.txt but it is not working . database : Oracle so please advice me how can i... (7 Replies)
Discussion started by: Himanshu_soni
7 Replies

10. Shell Programming and Scripting

Get SQL query result to file in putty

How to Get SQL query result to file in putty? I have one SQL query and I want that query output to be redirected to the file. uname -a SunOS XXX 5.8 Generic_117350-58 sun4u sparc SUNW,Sun-Fire-480R Please suggest. (7 Replies)
Discussion started by: pamu
7 Replies
NetSDS::DBI(3pm)					User Contributed Perl Documentation					  NetSDS::DBI(3pm)

NAME
NetSDS::DBI - DBI wrapper for NetSDS SYNOPSIS
use NetSDS::DBI; $dbh = NetSDS::DBI->new( dsn => 'dbi:Pg:dbname=test;host=127.0.0.1;port=5432', login => 'user', passwd => 'topsecret', ); print $db->call("select md5(?)", 'zuka')->fetchrow_hashref->{md5}; DESCRIPTION
"NetSDS::DBI" module provides wrapper around DBI module. CLASS API
new(%params) - class constructor $dbh = NetSDS::DBI->new( dsn => 'dbi:Pg:dbname=test;host=127.0.0.1;port=5432', login => 'user', passwd => 'topsecret', ); dbh() - DBI connection handler accessor Returns: DBI object This method provides accessor to DBI object and for low level access to database specific methods. Example (access to specific method): my $quoted = $db->dbh->quote_identifier(undef, 'auth', 'services'); # $quoted contains "auth"."services" now call($sql, @bind_params) - prepare and execute SQL query Method "call()" implements the following functionality: * check connection to DBMS and restore it * prepare chached SQL statement * execute statement with bind parameters Parameters: * SQL query with placeholders * bind parameters Return: * statement handler from DBI Example: $sth = $dbh->call("select * from users"); while (my $row = $sth->fetchrow_hashref()) { print $row->{username}; } fetch_call($sql, @params) - call and fetch result Paramters: SQL query, parameters Returns: arrayref of records as hashrefs Example: # SQL DDL script: # create table users ( # id serial, # login varchar(32), # passwd varchar(32) # ); # Now we fetch all data to perl structure my $table_data = $db->fetch_call("select * from users"); # Process this data foreach my $user (@{$table_data}) { print "User ID: " . $user->{id}; print "Login: " . $user->{login}; } begin() - start transaction commit() - commit transaction rollback() - rollback transaction quote() - quote SQL string Example: # Encode $str to use in queries my $str = "some crazy' string; with (dangerous characters"; $str = $db->quote($str); INTERNAL METHODS
_add_sets() - add initial SQL query Example: $obj->_add_sets("set search_path to myscheme"); $obj->_add_sets("set client_encoding to 'UTF-8'"); _add_attrs() - add DBI handler attributes $self->_add_attrs(AutoCommit => 1); _check_connection() - ping and reconnect Internal method checking connection and implement reconnect _connect() - connect to DBMS Internal method starting connection to DBMS EXAMPLES
samples/testdb.pl SEE ALSO
DBI, DBD::Pg TODO
1. Make module less PostgreSQL specific. AUTHOR
Michael Bochkaryov <misha@rattler.kiev.ua> LICENSE
Copyright (C) 2008-2009 Net Style Ltd. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA perl v5.10.1 2010-04-28 NetSDS::DBI(3pm)
All times are GMT -4. The time now is 02:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy