Solved

Korn script to write to an html file

Posted on 2013-05-10
6
470 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now