[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

KSH script to output report form SQL Plus

Posted on 2013-05-15
9
Medium Priority
?
1,996 Views
Last Modified: 2013-05-17
I have the following script creating an html file with data from an Oracle view, via SQL PLus:

#!/usr/bin/ksh

export ORACLE_SID=DBName
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF
CONNECT usr1/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
SPOOL myfile.html
SELECT * FROM my_view;
SPOOL OFF
EOF

mail -s "Subject" user@example.com < myfile.html

Open in new window


I have noticed that my report does not include column headings and was wondering how can I add them?

That's number 1, number 2 is that the e-mail gets sent in text format, not html format. How can I change that?
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
9 Comments
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 800 total points
ID: 39169710
SET PAGES 49999
0
 
LVL 7

Accepted Solution

by:
Docteur_Z earned 1000 total points
ID: 39170642
For the mail containing text and not an attached file, use uuencode :
uuencode myfile.html myfile.html | mail -s "Subject" user@example.com

Open in new window

0
 
LVL 35

Author Comment

by:YZlat
ID: 39171090
Mike, setting pages to 49999 didn't change anything
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 35

Author Comment

by:YZlat
ID: 39171100
Docteur_Z, with your code the html file came as an attachment to the e-mail and not as a body of the e-mail, It is good but is not exactly what I wanted
0
 
LVL 7

Expert Comment

by:Docteur_Z
ID: 39171187
Some implementation of mail have the --append option :
mail --append="Content-type: text/html" -s "Built notification" address@example.com 

Open in new window

If it hasn't got it, the only solution I see, is to "forge" the mail :
cat <<'EOF' test.html | mutt -H -
To: to@address
Subject: hello
Content-Type: text/html

EOF

Open in new window

Taken from
0
 
LVL 7

Expert Comment

by:Docteur_Z
ID: 39171198
For the colums header, did you tried the
set head on

Open in new window


And If you have size issues :
column colA heading "<p style='width:800px'>800SetColA</p>" format a40

Open in new window

0
 
LVL 35

Author Comment

by:YZlat
ID: 39171286
how can I see which options does the mail I use have?

man mail

didn't work
0
 
LVL 35

Assisted Solution

by:johnsone
johnsone earned 200 total points
ID: 39171583
Your script contains this line:
SET LINES 4000 TRIMS ON FEED OFF PAGES 0

Open in new window

The last part of that line PAGES 0 will suppress column headings.  If you added SET PAGES 49999 before that line, then this line would have overridden that setting.
0
 
LVL 35

Author Comment

by:YZlat
ID: 39172182
johnsone, thatnks for pointing that out! I just noticd it did. Great because i was very surprised something MikeOM_DBA suggested did not work, usually he is 100% on point:)
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 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.
Suggested Courses

656 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