SQL*Plus has traditionally been thought of as a plain text SQL query tool. But since Oracle 8i, it has also had the capability to render its output using HTML.

One of SQL*Plus's environment settings, MARKUP, controls what kind of mark-up language (if any) to use for its output. By default, MARKUP defines HTML as the mark-up language, but mark-up itself is turned off. A set of HTML tags is predefined; all you have to do is turn mark-up on by typing:

SET MARKUP HTML ON

and the tags will be added to each output produced by SQL*Plus. For example, after activating the feature as above, you could type the following:


SPOOL deptlist.html

SELECT * FROM departments;

SPOOL OFF

and the result would be formatted as an HTML table ready to add to an intranet or other Web page. To create a complete HTML document, including the <HTML> and </HTML> tags and a CSS style sheet, type:

SET MARKUP HTML ON SPOOL ON

To turn the feature off again or exit the session, type:

SET MARKUP HTML OFF

or

SET MARKUP HTML OFF SPOOL OFF

If you don't like the way that SQL*Plus formats the output, no problem. You can also use the SET MARKUP command to replace the built-in formatting codes with your own. The HEAD, BODY, TABLE, and other options let you specify the HTML to generate.

Database Jumping This was published in Database Jumping, check every Thursday for more stories

Related links

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

Log in


Sign up | Forgot your password?

What's on?