sql through unix.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sql through unix.
# 1  
Old 09-09-2008
sql through unix.

when we are spooling query o/p to certain txt file,in that file how we can get headers in the query.(through unix shell scripting).

for exmple

q1="slect * from XXXXXX;";

sqlplus XXX/XXXX@XXXXX

spool XXXX.txt
$q1
spool off

in the text file i want the headers of the query.....

plese suggest...

thanks in advance
# 2  
Old 09-09-2008
If you mean how to get sqlplus to display headers:
Code:
q1="slect * from XXXXXX;";

echo "
set pagesize 55
set head on
spool XXXX.txt
$q1
spool off
" | sqlplus i-s XXX/XXXX@XXXXX > file.txt

If you mean search the output for headers:
Code:
q1="slect * from XXXXXX;";

echo "
set pagesize 55
set head on
spool XXXX.txt
$q1
spool off
" | sqlplus i-s XXX/XXXX@XXXXX | \ 
awk 'BEGIN {old=""} { if( $0 ~ "^ --" ) {print old; print $0} old=$0}'


[/code]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

2. Shell Programming and Scripting

Formatting sql in UNIX

hi folks am running the shell script below #!/bin/bash sqlplus 'scott@orcl/tiger'<<ENDSQL >> outputlogfile.csv SET PAGES 0 SET HEAD ON SET ECHO OFF SET FEEDBACK OFF SET LINESIZE 100 SET PAGESIZE 100 SET SERVEROUTPUT ON --# Fire the query on database select * from employee; ... (2 Replies)
Discussion started by: coolboy98699
2 Replies

3. Shell Programming and Scripting

Unix and SQL server

Hi All, I am accessing Unix through putty (i.e. unix is installed on other server and i am accessing it remotely through putty). I am having SQL Server 2008 installed on my computer. Now i want to access sql server via. unix. Could some one please help me in this!!! Thanks (2 Replies)
Discussion started by: preetpalkapoor
2 Replies

4. Programming

Doing a SQL rollup in unix

If anyone is familiar with Oracle, there is a way to trace a file. Then there is is a script called tkprof that will generate a report that includes a rollup of some values. The problem with this script is that it only does the rollup properly if the query is finished. So I need something quick and... (2 Replies)
Discussion started by: guessingo
2 Replies

5. Shell Programming and Scripting

How to use sql data file in unix csv file as input to an sql query from shell

Hi , I used the below script to get the sql data into csv file using unix scripting. I m getting the output into an output file but the output file is not displayed in a separe columns . #!/bin/ksh export FILE_PATH=/maav/home/xyz/abc/ rm $FILE_PATH/sample.csv sqlplus -s... (2 Replies)
Discussion started by: Nareshp
2 Replies

6. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

7. Shell Programming and Scripting

unix variables from sql / pl/sql

How do I dynamically assign the below output to unix shell variables so I can build a menu in a shell script? Example: var1 = 1 var2= SYSTEM var3 = 2 var4= UNDOTBS1 and so on, then in the shell script I can use the variables to build a menu. set serveroutput on declare... (2 Replies)
Discussion started by: djehres
2 Replies

8. UNIX for Dummies Questions & Answers

SQL in Unix

Hi, I would like to access SQL plus from my unix, and learn to run some SQL scripts in Unix. How do i begin. Is there any known website that offers a quick tutorial or tips? Thanks, unxhopeful (4 Replies)
Discussion started by: unxhopeful
4 Replies

9. Shell Programming and Scripting

Using SQL in Unix

Please tell me how i can use SQL in my unix scripts. Please give examples. I just want to start writing some scripts for my use. Looking for ur cooperation. thanks (2 Replies)
Discussion started by: Mohit623
2 Replies

10. Shell Programming and Scripting

SQL Commands in Unix

Hi gurus, Being a newbie not sure whether iam asking the right question? can we use oracle commands in unix for ex: to read a count on a table. if so, what needs to be configured and etc.. any kind of help is appreciated. Thanks sish (6 Replies)
Discussion started by: sish78
6 Replies
Login or Register to Ask a Question