?
Solved

KSH script to output report form SQL Plus

Posted on 2013-05-15
9
Medium Priority
?
2,025 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
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

840 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