any possible to run sql result and output to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting any possible to run sql result and output to file
# 1  
Old 03-01-2007
any possible to run sql result and output to file

Hi,

I search all post...and no soluation about..if i would like to run a sql statement and output the result to txt file.

for example,
i usually run "sql" to logon the database and run select statement. Then I need to copy the output into the result.txt. Can I run the script to do this easiler?

Thx!
# 2  
Old 03-01-2007
Quote:
Originally Posted by happyv
Hi,

I search all post...and no soluation about..if i would like to run a sql statement and output the result to txt file.

for example,
i usually run "sql" to logon the database and run select statement. Then I need to copy the output into the result.txt. Can I run the script to do this easiler?

Thx!
I am not sure which sql you are trying to connect. just for an example i am using mysql

Code:
  echo "SELECT *  FROM employee WHERE \
     emp_name="XXXXX" \
	   |$MYSQL_PATH/mysql dbname --user='whoever' --password='whatever'  -v -v -v >$DIRNAME/$outputfile 2>&1

# 3  
Old 03-01-2007
Quote:
Originally Posted by ahmedwaseem2000
I am not sure which sql you are trying to connect. just for an example i am using mysql

Code:
  echo "SELECT *  FROM employee WHERE \
     emp_name="XXXXX" \
	   |$MYSQL_PATH/mysql dbname --user='whoever' --password='whatever'  -v -v -v >$DIRNAME/$outputfile 2>&1


thank..how can i check which sql I used?
# 4  
Old 03-02-2007
I am not sure how can we check which database is installed in the machine.Might be can find it from the bin directory...Guys , any idea?

Below is another approch to run an sql from unix prompt besides the above method..where new.sql is a text file containing the sql command.This approch will be useful if you have more than one query to run...

sqlplus username/password <new.sql
# 5  
Old 03-02-2007
There could be many database's present on the machine but what's the use when you dont know which sql you are going to use and incase, if you might not have the user id and password you cant even login to it. So, first you need to ask your dba which database you have to access and its right credentials!!!!
# 6  
Old 03-02-2007
Quote:
Originally Posted by jacoden
I am not sure how can we check which database is installed in the machine.Might be can find it from the bin directory...Guys , any idea?

Below is another approch to run an sql from unix prompt besides the above method..where new.sql is a text file containing the sql command.This approch will be useful if you have more than one query to run...

sqlplus username/password <new.sql
I tried sqlplus, but my existing sql database username and password...cannot work on sqlplus....so I think..I cannot use sqlplus command...

any advise?
# 7  
Old 03-02-2007
Quote:
Originally Posted by happyv
I tried sqlplus, but my existing sql database username and password...cannot work on sqlplus....so I think..I cannot use sqlplus command...

any advise?
no one can advise you when you dont have proper credentials, its only the DBA who can grant you the login.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run sql query in shell script and output data save as delimited text

I want to run sql query in shell script and output data save as delimited text (delimited text would be comma) Code: SPOOL_FILE=/pgedw/dan.txt SQL=/pgedw/dan.sql sqlplus -s username/password@myhost:port/servicename <<EOF set head on set COLSEP , set linesize 32767 SET TRIMSPOOL ON SET... (8 Replies)
Discussion started by: Jaganjag
8 Replies

2. 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

3. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

Write result to output file

Good morning everybody, Beeing an absolute newbie in shell scripting I would like to look for some help here. I would like to read an external text file and format the data and write it to an output file. What I was trying to do was to display the result (this worked). But now I... (1 Reply)
Discussion started by: bluejean1976
1 Replies

6. 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

7. Shell Programming and Scripting

Help! Paste Multiple SQL output result to exec command

Hi, I want to write the shell script to change multple file name (the file name is get from DB) e.g. cp db1.txt file1_new.txt cp db2.txt file2_new.txt cp db3.txt file3_new.txt I have write the script like this: VAR=`sqlplus -s $LOGON @<<ENDOFTEXT set termout off ... (0 Replies)
Discussion started by: jackyntk
0 Replies

8. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: dolphin123
1 Replies

9. 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

10. Shell Programming and Scripting

Run SQL queries in DB2 and output to file

Hi, I new to Unix and scripting. Following is my requirement. Can someone tell me whether its possible or not. Also please let me know how to proceed further if this is possible. List of queries are stored in a file. For example, I have to run a query like this: Select * from &XYZ where... (0 Replies)
Discussion started by: simhasuri
0 Replies
Login or Register to Ask a Question