Sqlplus Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sqlplus Help
# 1  
Old 07-26-2012
Error Sqlplus Help

When i run the following script am getiing the output correct but i want to get it in the form of a table, could any one help me please. the script is a s follows

Code:
count=`sqlplus -s $ORACLE_ACCOUNT << EOF
set heading off
set wrap on
set feedback off
column ChangeNumber format a12
column Summary format a20
column Status format a6
column Assert format a10
set pagesize 50000
set linesize 32000

select distinct c.chg_ref_num as ChangeNumber, c.summary as Summary, c.status as Status, n.NR_PRIM_SEARCH_KEY as Assert from chgalg al, chg c, net_res n where
c.id = al.change_id and c.zasset = n.id and (al.description like 'Status changed from%to%SL%' or al.description like 'Status changed from%to%SV%')
and al.time_stamp between
(Select (TO_DATE(to_char(trunc(sysdate-7)+(.041987 * 13),'dd/mm/rrrr HH24:MI:SS'), 'DD/MM/RRRR HH24:MI:SS')-TO_DATE('01/01/1970 00:00:00', 'DD/MM/RRRR HH24:MI:SS'))* 24 * 60 * 60 from dual)
and
(select (TO_DATE(to_char(trunc(sysdate),'dd/mm/rrrr HH24:MI:SS'),'dd/mm/rrrr HH24:MI:SS') - TO_DATE('01-JAN-1970 00:00:00', 'DD/MM/RRRR HH24:MI:SS')) * 24 * 60 * 60 from dual) order by c.chg_ref_num ;

exit;
EOF`
echo $count

output is:

Code:
58508 Ett fel i PINCA TGL2 SV PALS f�r Piloter och Cab in 61535 Use-Case Specificati CS CAM on: UC23 -
Message l ogging for Statistic s 62641 Use Default ACV inst CS COTI ead of fitted config uration from codesha
re partner SSIM7 63055 EuroBonus Welcom Int SL FLYSAS roduction_new movies to be added for SE 63134
AUDIT: Deletion of D CS SUPEROFFIC E old data E 63136 Reopen closed TPC in SL CODS CODS and migrate to TP account

In the output till the number its one row.

Last edited by Scott; 07-26-2012 at 07:35 AM.. Reason: Code tags, please.
# 2  
Old 07-26-2012
Quote your output when you echo it.
Code:
...
echo "$count"
...

# 3  
Old 07-26-2012
Am directly redirecting the output to $count, I do not know exactly the quote is...
# 4  
Old 07-26-2012
i could see the query which you provided doesnt contain the COUNT(*) . Please change the query to

Code:
select count(*) from (select distinct c.chg_ref_num as ChangeNumber, c.summary as Summary, c.status as Status, n.NR_PRIM_SEARCH_KEY as Assert from chgalg al, chg c, net_res n where
c.id = al.change_id and c.zasset = n.id and (al.description like 'Status changed from%to%SL%' or al.description like 'Status changed from%to%SV%')
and al.time_stamp between
(Select (TO_DATE(to_char(trunc(sysdate-7)+(.041987 * 13),'dd/mm/rrrr HH24:MI:SS'), 'DD/MM/RRRR HH24:MI:SS')-TO_DATE('01/01/1970 00:00:00', 'DD/MM/RRRR HH24:MI:SS'))* 24 * 60 * 60 from dual)
and
(select (TO_DATE(to_char(trunc(sysdate),'dd/mm/rrrr HH24:MI:SS'),'dd/mm/rrrr HH24:MI:SS') - TO_DATE('01-JAN-1970 00:00:00', 'DD/MM/RRRR HH24:MI:SS')) * 24 * 60 * 60 from dual) order by c.chg_ref_num);


Last edited by Scott; 07-26-2012 at 07:35 AM.. Reason: Code tags
# 5  
Old 07-26-2012
The query output is assigned to a variable called count and am printing it when i print it am getting the above mentioned output but i need it to be in a table format like in pl/sql like
Code:
CHANGENUMBER| SUMMARY| STATUS| ASSERT
-------------------------------------------------------------------
<some Number>| <summary>|<staus>|<assert>


Last edited by Scott; 07-26-2012 at 07:36 AM.. Reason: Code tags
# 6  
Old 07-26-2012
try this :

Code:
x=`sqlplus -s $ORACLE_ACCOUNT << EOF
set heading off
set wrap on
set feedback off
column ChangeNumber format a12
column Summary format a20
column Status format a6
column Assert format a10
set pagesize 50000
set linesize 32000
spool count.txt
select ChangeNumber||'|'||Summary||'|'Status||'|'||Assert from dual;

select ChangeNumber||'|'||Summary||'|'Status||'|'||Assert from (select distinct c.chg_ref_num as ChangeNumber, c.summary as Summary, c.status as Status, n.NR_PRIM_SEARCH_KEY as Assert from chgalg al, chg c, net_res n where
c.id = al.change_id and c.zasset = n.id and (al.description like 'Status changed from%to%SL%' or al.description like 'Status changed from%to%SV%')
and al.time_stamp between
(Select (TO_DATE(to_char(trunc(sysdate-7)+(.041987 * 13),'dd/mm/rrrr HH24:MI:SS'), 'DD/MM/RRRR HH24:MI:SS')-TO_DATE('01/01/1970 00:00:00', 'DD/MM/RRRR HH24:MI:SS'))* 24 * 60 * 60 from dual)
and
(select (TO_DATE(to_char(trunc(sysdate),'dd/mm/rrrr HH24:MI:SS'),'dd/mm/rrrr HH24:MI:SS') - TO_DATE('01-JAN-1970 00:00:00', 'DD/MM/RRRR HH24:MI:SS')) * 24 * 60 * 60 from dual) order by c.chg_ref_num );
spool off;
 
exit;

EOF`
 
cat count.txt


Last edited by Scott; 07-26-2012 at 07:36 AM.. Reason: Code tags
# 7  
Old 07-26-2012
Getting the following error
Code:
select ChangeNumber||'|'||Summary||'|'Status||'|'||Assert from dual
                                            *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected 


select ChangeNumber||'|'||Summary||'|'Status||'|'||Assert from (select distinct c.chg_ref_num as ChangeNumber, c.summary as Summary, c.status as Status, n.NR_PRIM_SEARCH_KEY as Assert from chgalg al, chg c, net_res n where
                                            *
ERROR at line 1:
ORA-00923: FROM keyword not found where expected


Last edited by Scott; 07-26-2012 at 07:37 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Problem on SQLplus command ""bash: sqlplus: command not found""

Hi all, i face an error related to my server ""it's running server"" when i use sqlplus command $ sqlplus bash: sqlplus: command not found the data base is up and running i just need to access the sqlplus to import the dump file as a daily backup. i already check the directory... (4 Replies)
Discussion started by: clerck
4 Replies

2. Shell Programming and Scripting

Sqlplus error - sqlplus -s <login/password@dbname> : No such file or directory

i am using bash shell Whenever i declare an array, and then using sqlplus, i am getting sqlplus error and return code 127. IFS="," declare -a Arr=($Variable1); SQLPLUS=sqlplus -s "${DBUSER}"/"${DBPASS}"@"${DBASE} echo "set head off ; " > ${SQLCMD} echo "set PAGESIZE 0 ;" >> ${SQLCMD}... (6 Replies)
Discussion started by: arghadeep adity
6 Replies

3. Shell Programming and Scripting

sqlplus: cannot execute

Hi, This is the content in my .profile on a unix server, MAIL=/usr/mail/${LOGNAME:?} umask 027 #added by enRole Agent PATH=${PATH}:/opt/app/p1crm1c3/informatica/oracle/product/10.2.0 export PATH PATH=$PATH:/opt/app/p1crm1c3/informatica/oracle/product/10.2.0/network/admin/sqlnet.ora;export... (2 Replies)
Discussion started by: yohasini
2 Replies

4. AIX

SQLPLUS problem

Hi guys, Here is the error i get by running a "sqlplus -v" after installing an oracle client 10.2.0.5 on an AIX 5.3.9 server. Could not load program sqlplus: Symbol resolution failed for sqlplus because: Symbol __pthread (number 307) is not exported from dependent ... (3 Replies)
Discussion started by: Chapel
3 Replies

5. Shell Programming and Scripting

sqlplus @ not working sqlplus \@ working..

Hi All, I am facing a strange problem on one of my unix servers. When i try to login using the standard method: it fails with below message >sqlplus REF1SSTDBO1/REF1SSTDBO1@TKS3N10G > TKS3N10G ksh: TKS3N10G: not found But it works perfectly when i escape with ;\ >sqlplus... (3 Replies)
Discussion started by: kunwar
3 Replies

6. Shell Programming and Scripting

SQLPLUS error

I am running a script that invokes SQLPLUS. During the execution I get the following: SQL*Plus: Release 9.2.0.8.0 - Production on Mon Jun 11 16:12:50 2007 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Connected to: Oracle9i Enterprise Edition Release 9.2.0.8.0 -... (3 Replies)
Discussion started by: ssmith001
3 Replies

7. HP-UX

how can i call sqlplus?

i am new working with hp-ux but i had to because of my job. so i want to execute some sql scripts but when i call sqlplus to run them it responds /sbin/sh: sqlplus not found. i have oracle 8.1.7 installed. what should i do sorry if this sounds too easy but i am now learning. The same... (13 Replies)
Discussion started by: theodore
13 Replies

8. Shell Programming and Scripting

Sqlplus

I am looking to loop round a load of files and execute each in sqlplus, I have looked at the forum to see what was posted in the past, but most of the examples seem to use the sql being passed in through the script, which is not really what I am looking for, can someone tell me if the code below is... (9 Replies)
Discussion started by: LiquidChild
9 Replies

9. Shell Programming and Scripting

Using a variable in sqlplus

Hello, I'm trying to write a script that will loop a sql statement through an external list. Basically, the script enters a loop and runs the sql statement for each entry in the list file. Currently, the script will stop at a cursor where I can then manually enter the SQL statment. This is... (11 Replies)
Discussion started by: MadHatter
11 Replies

10. Shell Programming and Scripting

Sqlplus

Hi all, I am new to SQLPLUS, can anyone tell me what is the following codes doing? DECLARE cursor c1 is select bts_int_id, max(ave_busy_tch/res_av_denom14) maxBusyTch from p_nbsc_res_avail where to_char(period_start_time,'yyyymmdd')=to_char((sysdate-1),'yyyymmdd') group by... (4 Replies)
Discussion started by: antkiu
4 Replies
Login or Register to Ask a Question