[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Korn script to write to an html file

Posted on 2013-05-10
6
Medium Priority
?
490 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 78

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 29

Accepted Solution

by:
MikeOM_DBA earned 2000 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 35

Author Comment

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Utilizing an array to gracefully append to a list of EmailAddresses
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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.
Suggested Courses
Course of the Month18 days, 8 hours left to enroll

825 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