Solved

How to modify the header in spool with Linux/Oracle?

Posted on 2013-12-13
5
483 Views
Last Modified: 2013-12-16
Hello, making a spool from the attached script,
should change the headers of the output, which now shows:

2013/09/24 17:30:00! 10027! 0! PSM_4SA4______I! 223.040253! # ..! 0! # ..! 0! # ..! 0! # ..!
2013/09/24 17:30:00! 10024! 0! PSM_4SA1______I! 167.887207! # ..! 0! # ..! 0! # ..! 0! # ..!

Open in new window


to show me the column names, separated by "!" :

UTCTime! pointnumber! pointname! valor_inst!tlq_inst!valor_prom!tlq_prom!valor_max!tlq_max!utctime_max!valor_min!tlq_min!utctime_min
2013/09/24 17:30:00! 10027! 0! PSM_4SA4______I! 223.040253! # ..! 0! # ..! 0! # ..! 0! # ..!
2013/09/24 17:30:00! 10024! 0! PSM_4SA1______I! 167.887207! # ..! 0! # ..! 0! # ..! 0! # ..!

Open in new window


What option would I use?
thanks
Test.sh
0
Comment
Question by:carlino70
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
sventhan earned 500 total points
ID: 39716674
Try this

Modify your script like this ... Add a another select for selecting all your headers as shown below ....

--host echo Copying out ANALOG_01
spool $OUTPUT/ANALOG_01_$FECHA.txt
select UTCTime! pointnumber! pointname! valor_inst!tlq_inst!valor_prom!tlq_prom!valor_max!tlq_max!utctime from dual
union all
SELECT
TO_CHAR(H.UTCTIME,'YYYY/MM/DD HH24:MI:SS')||'!'||TO_CHAR(H.POINTNUMBER)||'!'||S.POINTNAME||'!'||TO_CHAR(H.VALUE_INST)||'!'||ge_pkt_conv_funcs.f_convert_tlq(H.TLQ_INST)||'!'||TO_CHAR(H.VALUE_PROM)||'!'||ge_pkt_conv_funcs.f_convert_tlq(H.TLQ_PROM)||'!'||TO_CHAR(xa_time_cnv.utc_to_loc(H.UTCTIME_MAX),'YYYY/MM/DD HH24:MI:SS')||'!'||TO_CHAR(H.VALUE_MAX)||'!'||ge_pkt_conv_funcs.f_convert_tlq(H.TLQ_MAX)||'!'||TO_CHAR(xa_time_cnv.utc_to_loc(H.UTCTIME_MIN),'YYYY/MM/DD HH24:MI:SS')||'!'||TO_CHAR(H.VALUE_MIN)||'!'||ge_pkt_conv_funcs.f_convert_tlq(H.TLQ_MIN)||'!'
FROM ANALOG_01 H, xaJsdb.AnalogPoint S
WHERE H.POINTNUMBER = S.POINTNUMBER AND UTCTIME >= trunc(sysdate)-$T_ATRAS-1 AND UTCTIME < trunc(sysdate)-$T_ATRAS
ORDER BY UT
0
 
LVL 18

Expert Comment

by:sventhan
ID: 39716679
You can add quotes if you get any errors  like below for the header SQLs

select "UTCTime!", "pointnumber!" etc  from dual
0
 

Author Comment

by:carlino70
ID: 39716819
Thanks sventhan, look at this:

select 
'UTCTIME!POINTNUMBER!POINTNAME!VALOR_INST!TLQ_INST!VALOR_PROM!TLQ_PROM!UTCTIME_MAX!VALOR_MAX!TLQ_MAX!UTCTIME_MIN!VALOR_MIN!TLQ_MIN!'
from dual
union all
SELECT
TO_CHAR(H.UTCTIME,'YYYY/MM/DD HH24:MI:SS')||'!'||TO_CHAR(H.POINTNUMBER)||'!'||S.POINTNAME||'!'||TO_CHAR(H.VALOR_INST)||'!'||ge_pkt_conv_funcs.f_convert_tlq(H.TLQ_INST)||'!'||TO_CHAR(H.VALOR_PROM)||'!'||ge_pkt_conv_funcs.f_convert_tlq(H.TLQ_PROM)||'!'||TO_CHAR(xa_time_cnv.utc_to_loc(H.UTCTIME_MAX),'YYYY/MM/DD HH24:MI:SS')||'!'||TO_CHAR(H.VALOR_MAX)||'!'||ge_pkt_conv_funcs.f_convert_tlq(H.TLQ_MAX)||'!'||TO_CHAR(xa_time_cnv.utc_to_loc(H.UTCTIME_MIN),'YYYY/MM/DD HH24:MI:SS')||'!'||TO_CHAR(H.VALOR_MIN)||'!'||ge_pkt_conv_funcs.f_convert_tlq(H.TLQ_MIN)||'!'
FROM ANALOG_01 H, xaJsdb.AnalogPoint S
WHERE H.POINTNUMBER = S.POINTNUMBER AND H.UTCTIME >= trunc(sysdate)-1 AND H.UTCTIME < trunc(sysdate)
ORDER BY 1;

Open in new window

It works with "ORDER BY 1", instead "ORDER BY UTCTIME". Also all the headers must be contiguous inside single quote.
Regards.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39721348
Even though this has already been closed out I wanted to offer an alternate solution.

the PROMPT command outside of the SELECT.

In the original script you posted, after the SPOOL and before the SELECT:
prompt UTCTime! pointnumber! pointname! valor_inst!tlq_inst!valor_prom!tlq_prom!valor_max!tlq_max!utctime_max!valor_min!tlq_min!utctime_min

Open in new window

0
 

Author Comment

by:carlino70
ID: 39721377
Thanks slightwv, It is a good alternative idea.

Regards
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to take different types of Oracle backups using RMAN.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question