select in HTML format
Last Wednesday I selected data from an HTML table : select from xml
Today, let’s try the opposite, generate an HTML table from a SQL query
select
XMLSERIALIZE(
DOCUMENT
XMLROOT(
XMLTRANSFORM(
XMLTYPE(
CURSOR(
SELECT * FROM DEPT
)
),
XMLTYPE.CREATEXML(
'<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<html>
<head>
<title>Table DEPT</title>
</head>
<body>
<p>Table DEPT in HTML format</p>
<table border="1">
<tr>
<th align="right">DEPTNO</th>
<th align="left">DNAME</th>
<th align="left">LOC</th>
</tr>
<xsl:for-each select="/ROWSET/ROW">
<tr>
<td align="right"><xsl:value-of select="DEPTNO"/></td>
<td align="left"><xsl:value-of select="DNAME"/></td>
<td align="left"><xsl:value-of select="LOC"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>'
)
)
, VERSION '1.0')
)
from DUAL;
Table DEPT in HTML format
| DEPTNO | DNAME | LOC |
|---|---|---|
| 10 | ACCOUNTING | NEW YORK |
| 20 | RESEARCH | DALLAS |
| 30 | SALES | CHICAGO |
| 40 | OPERATIONS | BOSTON |
Largely inspired from xmlfiles.com
Wow, that was easy!
Laurent, what about:
>set markup html on
>select * from emp;
sure, if you are using sqlplus