Solved

Korn script to write to an html file

Posted on 2013-05-10
6
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 77

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 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 35

Author Comment

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Via a live example, show how to take different types of Oracle backups using RMAN.
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.

696 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