Solved

Korn script to write to an html file

Posted on 2013-05-10
6
475 Views
Last Modified: 2013-05-10
I have a ksh script that reads data from an Oracle database and outputs it to a text file. I would like it to output data to an html file instead. How can I accomplish that?

Here is my script:

#!/usr/bin/ksh

if [ $# -gt 0 ]
then
	export ORACLE_SID=$1
	ORAENV_ASK=NO
	. oraenv
	sqlplus -s /nolog <<EOF
	connect username/pwd
	set lines 4000
	set trimspool on
	set feedback off
	set pages 0

	spool myfile.dat
	SELECT * from my_view;
	spool off
EOF

fi  

Open in new window

0
Comment
Question by:YZlat
6 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39155989
It will probably need some tweaking but add the following to the sqlplus set parameters:
set markup html on
0
 
LVL 11

Expert Comment

by:netballi
ID: 39156021
0
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 39156492
Try this:
#!/usr/bin/ksh

if [ $# -lt 1 ]
then
  echo "!Error: missing parameter 1-{sid}"
  exit 1
fi  
export ORACLE_SID=$1
ORAENV_ASK=NO
. /usr/local/bin/oraenv
sqlplus -s /nolog <<EOF
CONNECT username/pwd
SET LINES 4000 TRIMS ON FEED OFF PAGES 0
SET MARKUP HTML ON SPOOL ON HEAD "<TITLE>SQL*Plus Report</title> -
<STYLE TYPE='TEXT/CSS'><!--BODY {background: ffffc6} --></STYLE>"
SET ECHO OFF
SPO myfile.html
SELECT * FROM my_view;
SPO OFF
EOF

Open in new window

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

 
LVL 35

Author Comment

by:YZlat
ID: 39156722
what does SPO command do?
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39156739
>>what does SPO command do?

It's short for spool off.  You only need the first few characters of a command for sqlplus to recognize it.
0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 39156858
Thanks!
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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

839 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