How to get sql command with output in files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get sql command with output in files?
# 8  
Old 11-08-2013
You can use "!" before unix command as shown by rbatte for "echo" command
# 9  
Old 11-11-2013
There should be a note of caution though if you are planning to use the result of your shell commands back into the second part of the SQL, similar to this:-
Code:
column="COL1"
sqlplus <<-EOSQL
$username/$password
select $column from my_table;
!column="COL2"
select $column from my_table;
EOSQL

I think that the variables in the section before the EOSQL label (called a Here document) will be evaluated by the shell before the sqlplus command is called, so you will actually still select COL1 for the second line.


I hope that this gives you something to consider. It may be that there is still a need to execute as separate queries if this is the case. The alternate would be to have a reference table in your database and then when you ! out to the shell, call another SQL to update this table before returning to the main execution. It's not pretty, but it might work.

Many things are achievable from within SQL already. What are you trying to do in the shell? It might be that we can capture it into the SQL.




Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

2. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

3. Shell Programming and Scripting

Compare 2 files using sdiff command output

Hi All, I have written the shell script which does the following : a. Reads the *.cnf file content from the specified input folder path b. Grep's some strings from the *.cnf file and writes the output in result file(*.cnf_result.txt) in output folder c. Now, if we get new version of... (5 Replies)
Discussion started by: Optimus81
5 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

list files command output

Hi All, Below is the 2 different ouputs of the command "ls -lrt", my question is what exactly "total 0" & "total 8" means here ? $ ls -rtl total 0 -rw-r--r-- 1 oracle dba 0 Feb 10 20:16 c -rw-r--r-- 1 oracle dba 0 Feb 10 20:16 b -rw-r--r-- 1... (1 Reply)
Discussion started by: kannan84
1 Replies

6. Shell Programming and Scripting

sql select command output formatting in shell script

Hi, I need to connect to the database and retrieve two variables from the database and store them in a variable,out of these two variables I need to get lastdigit appended to the variable 1 retrieved and variable 2 with out any modification in short select var,data from usage; o/p=... (1 Reply)
Discussion started by: rkrish
1 Replies

7. Shell Programming and Scripting

Unix shell command output to a sql statement

Can i do this Say one command sed 's/:*/ /g' $summf is returning C1234 C2345 C3434 some no of rows, now this ouput i have to insert it into a DB table how do i do this?? (2 Replies)
Discussion started by: depakjan
2 Replies

8. Shell Programming and Scripting

join files cisco command output

We have two files with results of two commands of cisco: one file; showintstatus, have the following format: Gi2/6 servidorlij connected 176 full 1000 10/100/1000BaseTsecond file; showmacaddrestable, have the following format: * 162 0021.9b8d.073e dynamic Yes 0 ... (1 Reply)
Discussion started by: robonet
1 Replies

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

10. Shell Programming and Scripting

Execute command created from sql output

Hi, I've would like to create kill statement from sqlplus output. So, I've modified somoene's script : mud_kill_stmt=`sqlplus -s / as sysdba <<EOF select 'kill -9 ' || p.SPID || ';' statement from $process_view p, $session_ ......... and so on exit; EOF` $mud_kill_stmt | tr ... (1 Reply)
Discussion started by: Arkadiusz Masny
1 Replies
Login or Register to Ask a Question