sql output in the same line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sql output in the same line
# 1  
Old 08-26-2010
Data sql output in the same line

Hi All,

this is my first post...

i want the count output like the following:

Code:
COUNT(*)                   COUNT(*)
----------                 ---------
0                          120

The code is as follows:

Code:
# count the records in myemptable
$ORACLE_HOME/bin/sqlplus -SILENT /NOLOG << EOF > /tmp/temp_output
connect scott/tiger@orcl
set echo off
set serveroutput on
set feedback off
set timing off
set pagesize 3000
set linesize 100
set trimspool on
set tab off
set heading on

select count(*) from MYEMPTABLE where date_entered = sysdate;

select count(*) from MYEMPTABLE where date_entered = sysdate - 7;
EOF

cat /tmp/temp_output

i am getting the output presently as
Code:
COUNT(*)                   
    ----------                      
        100    

COUNT(*)          
    ----------                       
         120


Last edited by Scott; 08-27-2010 at 02:57 AM.. Reason: Please use code tags
# 2  
Old 08-27-2010
The problem is with your SQL!

Try the following:
Code:
Select CSD.CountSD, CSDS.CountSDS
From (select count(*) CountSD from MYEMPTABLE where date_entered = sysdate) CSD,
	(select count(*) CountSDS from MYEMPTABLE where date_entered = sysdate - 7) CSDS;

Regards.
# 3  
Old 08-27-2010
And an Oracle query that does a single pass through your table is as follows -

Code:
select sum(case when date_entered = sysdate
                then 1 else 0
           end) count1,
       sum(case when date_entered = sysdate - 7 
                then 1 else 0
           end) count2
   from myemptable;

Although I suspect you'd need the TRUNC function around the dates to get the correct result, like so -

Code:
select sum(case when trunc(date_entered) = trunc(sysdate)
                then 1 else 0
           end) count1,
       sum(case when trunc(date_entered) = trunc(sysdate - 7) 
                then 1 else 0
           end) count2
   from myemptable;

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Sql query output count

Hi Team, below sql rerturn 20 records, the result set i am going to assign to one variable and it showing count is 1. and i don't use count() in sql query... based on count, i need to fail the script. No_of_step=`echo ${g_count} | wc -l` function gf_count() { g_count=`sqlplus -s... (8 Replies)
Discussion started by: bmk123
8 Replies

3. Shell Programming and Scripting

Sending sql output to email body with conditional subject line

hi , i have written below piece of code to meet the requirement but i am stuck in the logic here. the requirement are: 1) to send the sql out put to email body with proper formatting. 2) if count_matching = Yes then mail should triggered with the subject line ... (10 Replies)
Discussion started by: itzkashi
10 Replies

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

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

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

7. Shell Programming and Scripting

SQL*PLUS Spool Output

Hi, Im writing a script to run a bit of sql(via sqlplus) that pulls back some data and spools it to a file, I want the spool file to only display the data, with no sql command at the top and no reports at the bottom ie(# of records recieved). I am currently doing it via a grep command but... (1 Reply)
Discussion started by: Magezy
1 Replies

8. Shell Programming and Scripting

Need SQL output without the header.

Hi, In a script i am trying to run a SQL by connecting Sybase DB. While executing the script I am getting the output with the header. means: Employee_Name--------------------------- Anup Das I need the Output: Anup Das Kindly advice. (2 Replies)
Discussion started by: anupdas
2 Replies

9. Shell Programming and Scripting

SQL output vertically aligned?

I used the SQL query (taken from other threads here) to get the expected values to be written into a file. myQuery=`sqlplus -s cr_appsrvr/appsrvr@qwi << EndofFile set heading off; set tab off; set wrap off; set pages 0; set feedback off; SELECT CLEARINGHOUSE_TRACE_NUM, INSURED_ID FROM... (4 Replies)
Discussion started by: swame_sp
4 Replies

10. Shell Programming and Scripting

sql output into a variable

i have to do a check in my UNIX script to see whats saved in the database. depending on whats there will fork data to certain functions. However i do not know how to capture SQL output into a UNIX variable. Below is what i have tried, but i get an error: Error 3706 Failure 3706 Syntax error:... (3 Replies)
Discussion started by: purplebirky
3 Replies
Login or Register to Ask a Question