Solved

KSH script to output report form SQL Plus

Posted on 2013-05-15
9
1,828 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 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 34

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't Access My Database 57 76
upgrading Oracle 10g/ 11g / 11g R2 to Oracle 12c 25 69
join a table with user_tab_columns in oracle 3 48
Renaming with batch file 4 39
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

809 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