konhon

          忘掉過去,展望未來。找回自我,超越自我。
          逃避不一定躲的過, 面對不一定最難過, 孤單不一定不快樂, 得到不一定能長久, 失去不一定不再擁有, 可能因為某個理由而傷心難過, 但我卻能找個理由讓自己快樂.

          Google

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            203 Posts :: 0 Stories :: 61 Comments :: 0 Trackbacks

          也許你還不知道 - sqlplus的小秘密(4)

          這個也許不算什么秘密, 很多人大概都知道, 不過用過的人也許不多.

          在8.1.7版本(也許是816? 不太確定)以后, sql*plus中有一個set markup html的命令, 可以將sql*plus的輸出以html格式展現.


          scott@O9I.US.ORACLE.COM> set markup html on spool on
          ">scott@O9I.US.ORACLE.COM&gt; select empno, ename from emp where rownum<3;
          <br>
          <p>
          <table border='1' width='90%' align='center' summary='Script output'>
          <tr>
          <th scope="col">
          EMPNO
          </th>
          <th scope="col">
          ENAME
          </th>
          </tr>
          <tr>
          <td align="right">
          7369
          </td>
          <td>
          SMITH
          </td>
          </tr>
          <tr>
          <td align="right">
          7499
          </td>
          <td>
          ALLEN
          </td>
          </tr>
          </table>
          <p>

          注意其中的spool on, 當在屏幕上輸出的時候, 我們看不出與不加spool on有什么區別, 但是當我們使用spool filename 輸出到文件的時候, 會看到spool文件中出現了<html><body>等tag.

          ">scott@O9I.US.ORACLE.COM&gt; spool c:emp.htm
          <br>
          ">scott@O9I.US.ORACLE.COM&gt; /
          <br>
          <p>
          <table border='1' width='90%' align='center' summary='Script output'>
          ......此處省略

          ">scott@O9I.US.ORACLE.COM&gt; spool off
          <br>

          查看生成的emp.htm文件的內容:

          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-936">
          <meta name="generator" content="SQL*Plus 9.2.0">
          <style type='text/css'> body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1 {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}</style><title>SQL*Plus Report</title>
          </head>
          <body>
          ">scott@O9I.US.ORACLE.COM&gt; /
          <br>
          <p>
          <table border='1' width='90%' align='center' summary='Script output'>
          <tr>
          <th scope="col">
          EMPNO
          </th>
          <th scope="col">
          ENAME
          </th>
          </tr>
          <tr>
          <td align="right">
          7369
          </td>
          <td>
          SMITH
          </td>
          </tr>
          <tr>
          <td align="right">
          7499
          </td>
          <td>
          ALLEN
          </td>
          </tr>
          </table>
          <p>

          ">scott@O9I.US.ORACLE.COM&gt; spool off
          <br>
          </body>
          </html>

          用ie打開emp.htm文件后的樣式如下:

          現在看看spool off的情況下:

          ">scott@O9I.US.ORACLE.COM&gt; set markup html on spool off
          <br>
          ">scott@O9I.US.ORACLE.COM&gt; spool c:emp2.htm
          <br>
          ">scott@O9I.US.ORACLE.COM&gt; /
          <br>
          <p>
          <table border='1' width='90%' align='center' summary='Script outpu
          ......此處省略
          ">scott@O9I.US.ORACLE.COM&gt; spool off
          <br>
          ">scott@O9I.US.ORACLE.COM&gt;

          查看生成的emp2.htm文件的內容:

          ">scott@O9I.US.ORACLE.COM&gt; /
          <br>
          <p>
          <table border='1' width='90%' align='center' summary='Script output'>
          <tr>
          <th scope="col">
          EMPNO
          </th>
          <th scope="col">
          ENAME
          </th>
          </tr>
          <tr>
          <td align="right">
          7369
          </td>
          <td>
          SMITH
          </td>
          </tr>
          <tr>
          <td align="right">
          7499
          </td>
          <td>
          ALLEN
          </td>
          </tr>
          </table>
          <p>

          ">scott@O9I.US.ORACLE.COM&gt; spool off

          由于這段代碼中沒有html文件頭, 所以我們可以直接作為內容插入到網頁中, 現在我們就可以把這段代碼放到下面作為示例:

          EMPNO ENAME
          7369 SMITH
          7499 ALLEN

          總結: 如果要生成一個完整的html文件, 就使用spool on選項, 如果只是要內容部分(用來添加到一個現有的網頁中), 那么就使用spool off選項.

          另外, set markup html還有很多選項可以用來定制生成的html的各個部分, 例如head, body, table等, 這里不再逐一說明, 詳細信息可以參考SQL*Plus User's Guide and Reference.

          適用場景: 當需要定時更新一個從數據庫中獲取內容的靜態頁面時, 這種方法絕對是快捷的并且容易實現的.

          posted on 2005-10-17 05:53 konhon 優華 閱讀(421) 評論(0)  編輯  收藏 所屬分類: Oracle
          主站蜘蛛池模板: 四子王旗| 黑龙江省| 临高县| 西青区| 阜阳市| 平果县| 普安县| 肃宁县| 定西市| 吉木乃县| 泸西县| 信阳市| 尤溪县| 兴隆县| 紫阳县| 和龙市| 凤台县| 日土县| 集贤县| 日喀则市| 霍邱县| 若羌县| 辽宁省| 和硕县| 南和县| 东平县| 乐至县| 碌曲县| 海原县| 平谷区| 莲花县| 镇江市| 安义县| 开化县| 龙游县| 南汇区| 交口县| 丹凤县| 茂名市| 金湖县| 东丰县|