Solved

Korn script to write to an html file

Posted on 2013-05-10
6
478 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 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle numeric condition check 4 36
SQL query for highest sequence 4 62
plsql job on oracle 18 76
Cannot connect to Oracle database, python not recognizing cx_Oracle 2 30
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…
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.
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

749 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