Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6695269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:12:05+00:00 2026-05-26T06:12:05+00:00

It seems really easy if you are using SQL*Plus to use SQL> set markup

  • 0

It seems really easy if you are using SQL*Plus to use

SQL> set markup html on;

and get some lovely results to the SQL*Plus window. we have an oracle job that runs overnight and sends an email of results to a number of people. I would like to wrap a sql statement in an HTML table to be in that message. What is the best way of doing that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:12:06+00:00Added an answer on May 26, 2026 at 6:12 am

    From posting over On the DBA site I got close to the answer that I was looking for. Tom Kyte has a great blog post with a function that does exactly what I was hoping for. In short here is what I implemented:

    I created a function that took a sys_refcursor as a variable:

    CREATE OR REPLACE FUNCTION fncRefCursor2HTML(rf SYS_REFCURSOR)  RETURN CLOB
    IS
        lRetVal      CLOB;
        lHTMLOutput  XMLType; 
        lXSL         CLOB;
        lXMLData     XMLType;
    
        lContext     DBMS_XMLGEN.CTXHANDLE;
    BEGIN
        -- get a handle on the ref cursor --
        lContext := DBMS_XMLGEN.NEWCONTEXT(rf);
        -- setNullHandling to 1 (or 2) to allow null columns to be displayed --
        DBMS_XMLGEN.setNullHandling(lContext,1);
        -- create XML from ref cursor --
        lXMLData := DBMS_XMLGEN.GETXMLTYPE(lContext,DBMS_XMLGEN.NONE);
    
        -- this is a generic XSL for Oracle's default XML row and rowset tags --
        -- " " is a non-breaking space --
        lXSL := lXSL || q'[<?xml version="1.0" encoding="ISO-8859-1"?>]';
        lXSL := lXSL || q'[<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">]';
        lXSL := lXSL || q'[ <xsl:output method="html"/>]';
        lXSL := lXSL || q'[ <xsl:template match="/">]';
        lXSL := lXSL || q'[ <html>]';
        lXSL := lXSL || q'[  <body>]';
        lXSL := lXSL || q'[   <table border="1">]';
        lXSL := lXSL || q'[     <tr bgcolor="cyan">]';
        lXSL := lXSL || q'[      <xsl:for-each select="/ROWSET/ROW[1]/*">]';
        lXSL := lXSL || q'[       <th><xsl:value-of select="name()"/></th>]';
        lXSL := lXSL || q'[      </xsl:for-each>]';
        lXSL := lXSL || q'[     </tr>]';
        lXSL := lXSL || q'[     <xsl:for-each select="/ROWSET/*">]';
        lXSL := lXSL || q'[      <tr>]';    
        lXSL := lXSL || q'[       <xsl:for-each select="./*">]';
        lXSL := lXSL || q'[        <td><xsl:value-of select="text()"/> </td>]';
        lXSL := lXSL || q'[       </xsl:for-each>]';
        lXSL := lXSL || q'[      </tr>]';
        lXSL := lXSL || q'[     </xsl:for-each>]';
        lXSL := lXSL || q'[   </table>]';
        lXSL := lXSL || q'[  </body>]';
        lXSL := lXSL || q'[ </html>]';
        lXSL := lXSL || q'[ </xsl:template>]';
        lXSL := lXSL || q'[</xsl:stylesheet>]';
    
        -- XSL transformation to convert XML to HTML --
        lHTMLOutput := lXMLData.transform(XMLType(lXSL));
        -- convert XMLType to Clob --
        lRetVal := lHTMLOutput.getClobVal();
    
        RETURN lRetVal;
    END;
    

    Then to test it in a Test window in PL/SQL Developer

    declare 
      l_cursor sys_refcursor;
    begin
      open l_cursor for select * from employees;
      :x:= fncRefCursor2HTML(l_cursor);
      close l_cursor;  
    end;
    

    This is something that I have been hoping to find for a long time. THANKS Tom Kyte!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are looking into using an ORM and I wanted some opinions/comparisons The basic
I'm using SQL Server 2005, with a case sensitive database.. In a search function,
Seems like this should be easy or at least documented somewhere, I just cant
I recently switched over to using Janus from a custom set of vim plugins
I've started using Mercurial for version-controlling my Drupal project source files (I'm both a
I have a project idea, but unsure if using Python would be a good
I'm doing an academic project which focus on providing some enhanced LBS services for
I'm having a little trouble with a SQL query, and thought I'd solicit the
I made a website that has a hierarchical structure and has search engine friendly
A while ago I wrote an app that relied on XML coming out of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.