Solved

KSH script to output report form SQL Plus

Posted on 2013-05-15
9
1,849 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 200 total points
ID: 39169710
SET PAGES 49999
0
 
LVL 7

Accepted Solution

by:
Docteur_Z earned 250 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 50 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example, show how to take different types of Oracle backups using RMAN.
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

733 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