Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Vanka.

Asked: October 12, 2016 - 7:05 pm UTC

Last updated: October 15, 2016 - 1:40 am UTC

Version: Oracl12c

Viewed 1000+ times

You Asked

Hi Guys,

I am using linux to run the query.
I have one query like select * from Emp;
I want to spool the results into one file(this file has only exported data without number of rows selected message) and what ever the log i.e number of lines selected or error msg into another file.

how to get it done? could any one suggest me how to go.

I have tried below code but it is not working and i do not want to use count(*) in query.

sqlplus -s paml/aml12345@amladev<< EOF
set verify off
set colsep ","
set linesize 32000
set pagesize 40000
set feedback off
set serveroutput off
set heading off
COLUMN row_cnt_col NOPRINT NEW_VALUE row_cnt
spool $RBACKUP
select EMPNO, COUNT(*) OVER() AS row_cnt_col from EMP;
spool off
spool $RLOG
SELECT 'Number of lines exported : ' ||&row_cnt AS "total_rows_found" FROM dual;
spool off
EXIT;
EOF



Thanks:)

and Connor said...

Probably the most efficient way would be do this in a post-processing step in the OS, for example:

sqlplus -s ... << EOF
set verify off
spool $RBACKUP
...
spool off
EXIT;
EOF

if [ "`grep 'ORA-' $RBACKUP`" ] ;then
   echo We had an error
   mailx -s "ERROR" joe@support.com < $RBACKUP
   exit 1
fi

linecount=`wc -l $RBACKUP`
echo "Number of lines exported : $linecount" >> $RLOG


Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Jony, October 13, 2016 - 11:30 am UTC

Suppose we create a procedure take a 2 minute to run and get 10,000 rows from multiple tables and applying a aggregate functions and lots of group by clause.
Now my question is when this query runs our OS CPU time is goes to 100 percentage but i want to assign some resources to the procedure which never goes to 20% of cpu
how to possible to assign cpu and other resource to particular procedure?
Connor McDonald
October 15, 2016 - 1:40 am UTC

Check out resource manager

http://docs.oracle.com/database/121/ADMIN/dbrm.htm#ADMIN027

You can control the CPU allocation (and many other things) to ensure that everyone gets a fair slice of the server "pie".