<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-88  評(píng)論-77  文章-48  trackbacks-0
    也許你還不知道 - sqlplus的小秘密(1)
    ===========================================================
    作者: oldwain(
    http://blog.itpub.net/oldwain )
    發(fā)表于:2005.09.05 15:09
    分類(lèi):
    出處:
    http://blog.itpub.net/post/6/40158
    ---------------------------------------------------------------

    有沒(méi)有為了dbms_output.put_line會(huì)"吃掉"最前面的空格而苦惱?
    						代碼:

    [ email ] scott @ O9I . US . ORACLE . COM [/ email ]> set serveroutput on
    [ email ] scott @ O9I . US . ORACLE . COM [/ email ]> exec dbms_output . put_line ( '???abc'
    );
    abc

    PL
    / SQL procedure successfully completed
    .




    (俺以前曾經(jīng)很苦惱為了保留空格, 嘗試了加".", 加不可見(jiàn)字符等辦法, 不過(guò)終究覺(jué)得不自然)
    實(shí)際上, 只要在set serveroutput on后加上format wrapped參數(shù), 就可以避免這個(gè)問(wèn)題
    						代碼:

    [ email ] scott @ O9I . US . ORACLE . COM [/ email ]> set serveroutput on format wrapped
    [ email ] scott @ O9I . US . ORACLE . COM [/ email ]> exec dbms_output . put_line ( '???abc'
    );
    ???
    abc

    PL
    / SQL procedure successfully completed
    .


    (需要引用, 請(qǐng)注明出處: http://blog.itpub.net/oldwain )

    也許你還不知道 - sqlplus的小秘密(2)
    ===========================================================
    作者: oldwain(http://blog.itpub.net/oldwain)
    發(fā)表于:2005.09.06 10:06
    分類(lèi):
    出處:http://blog.itpub.net/post/6/40252
    ---------------------------------------------------------------

    Sql*plus中, 不允許sql語(yǔ)句中間有空行, 這在從其它地方拷貝腳本到sql*plus中執(zhí)行時(shí)很麻煩. 比如下面的腳本:

    select deptno, empno, ename
    from emp

    where empno = '7788';
    如果拷貝到sql*plus中執(zhí)行, 就會(huì)出現(xiàn)錯(cuò)誤:


    scott@O9I.US.ORACLE.COM> select deptno, empno, ename
    2 from emp
    3
    scott@O9I.US.ORACLE.COM> where empno = '7788';
    SP2-0734: unknown command beginning "where empn..." - rest of line ignored.
    scott@O9I.US.ORACLE.COM>

    原因是sqlplus遇到空行就認(rèn)為是語(yǔ)句結(jié)束了.
    其實(shí)要改變這種現(xiàn)象, 只要使用SQLBLANKLINES參數(shù)就可以了
    scott@O9I.US.ORACLE.COM> SET SQLBLANKLINES ON
    scott@O9I.US.ORACLE.COM>
    scott@O9I.US.ORACLE.COM> select deptno, empno, ename
    2 from emp
    3
    4 where empno = '7788';

    DEPTNO EMPNO ENAME
    ---------- ---------- ----------
    20 7788 SCOTT

    scott@O9I.US.ORACLE.COM>
    (需要引用, 請(qǐng)注明出處: http://blog.itpub.net/oldwain)

    也許你還不知道 - sqlplus的小秘密(3)
    ===========================================================
    作者: oldwain(http://blog.itpub.net/oldwain)
    發(fā)表于:2005.09.07 10:04
    分類(lèi):
    出處:http://blog.itpub.net/post/6/40364
    ---------------------------------------------------------------

    有沒(méi)有過(guò)這樣的經(jīng)歷? 在sql*plus中敲了很長(zhǎng)的命令后, 突然發(fā)現(xiàn)想不起某個(gè)列的名字了, 如果取消當(dāng)前的命令,待查詢(xún)后再重敲, 那太痛苦了. 當(dāng)然你可以另開(kāi)一個(gè)sql*plus窗口進(jìn)行查詢(xún), 但這里提供的方法更簡(jiǎn)單.

    比如說(shuō), 你想查工資大于4000的員工的信息, 輸入了下面的語(yǔ)句:

    scott@O9I.US.ORACLE.COM> select deptno,
    2 empno,
    3 ename
    4 from emp
    5 where
    這時(shí), 你發(fā)現(xiàn)你想不起來(lái)工資的列名是什么了.

    這種情況下, 只要在下一行以#開(kāi)頭, 就可以執(zhí)行一條sql*plus命令, 執(zhí)行完后, 剛才的語(yǔ)句可以繼續(xù)輸入


    scott@O9I.US.ORACLE.COM> select deptno,
    2 empno,
    3 ename
    4 from emp
    5 where
    6 #desc emp
    Name Null? Type
    ----------------------------------------- -------- --------------

    EMPNO NOT NULL NUMBER(4)
    ENAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)

    6 sal > 4000;

    DEPTNO EMPNO ENAME
    ---------- ---------- ----------
    10 7839 KING

    scott@O9I.US.ORACLE.COM>
    (需要引用, 請(qǐng)注明出處: http://blog.itpub.net/oldwain)


    也許你還不知道 - sqlplus的小秘密(4)
    ===========================================================
    作者: oldwain(
    http://blog.itpub.net/oldwain )
    發(fā)表于:2005.09.08 12:54
    分類(lèi):
    出處:
    http://blog.itpub.net/post/6/40485
    ---------------------------------------------------------------

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

    這個(gè)也許不算什么秘密, 很多人大概都知道, 不過(guò)用過(guò)的人也許不多.

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

    												代碼:

    [ email ] scott @ O9I . US . ORACLE . COM [/ email ]> 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>"
    > scott @ O9I . US . ORACLE . COM & gt
    ;


    注意其中的spool on, 當(dāng)在屏幕上輸出的時(shí)候, 我們看不出與不加spool on有什么區(qū)別,
    但是當(dāng)我們使用spool filename 輸出到文件的時(shí)候, 會(huì)看到spool文件中出現(xiàn)了<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



    查看生成的emp.htm文件的內(nèi)容:

    												代碼:

    < 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打開(kāi)emp.htm文件后的樣式如下:

    http://blog.itpub.net/resserver.php?blogId=6&resource=sqlplushtml.JPG

    現(xiàn)在看看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.OR


    查看生成的emp2.htm文件的內(nèi)容:

    												代碼:

    ">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 ;

    																				代碼:



    由于這段代碼中沒(méi)有html文件頭, 所以我們可以直接作為內(nèi)容插入到網(wǎng)頁(yè)中.

    總結(jié): 如果要生成一個(gè)完整的html文件, 就使用spool on選項(xiàng), 如果只是要內(nèi)容部分(用來(lái)添加到一個(gè)現(xiàn)有的網(wǎng)頁(yè)中), 那么就使用spool off選項(xiàng).

    另外, set markup html還有很多選項(xiàng)可以用來(lái)定制生成的html的各個(gè)部分, 例如head, body, table等, 這里不再逐一說(shuō)明, 詳細(xì)信息可以參考SQL*Plus User's Guide and Reference.

    適用場(chǎng)景: 當(dāng)需要定時(shí)更新一個(gè)從數(shù)據(jù)庫(kù)中獲取內(nèi)容的靜態(tài)頁(yè)面時(shí), 這種方法絕對(duì)是快捷的并且容易實(shí)現(xiàn)的.

    (需要引用, 請(qǐng)注明出處:
    http://blog.itpub.net/oldwain )

    posted on 2006-04-27 10:03 崛起的程序員 閱讀(273) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): oracle

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产亚洲色视频在线| 亚洲欧洲日产韩国在线| 国产一级做a爱免费视频| 亚洲精品高清国产麻豆专区| 中文字幕在线观看亚洲日韩| 久久国产高潮流白浆免费观看| 成年私人影院免费视频网站| 亚洲国产日韩精品| 久久久www成人免费毛片| 亚洲精彩视频在线观看| 1000部禁片黄的免费看| 亚洲欧洲自拍拍偷午夜色| 四虎成年永久免费网站| 亚洲综合色丁香婷婷六月图片| 免费鲁丝片一级观看| 立即播放免费毛片一级| 中文字幕成人免费视频| 亚洲一本之道高清乱码| 日本高清免费网站| 一级毛片大全免费播放| 人人狠狠综合久久亚洲婷婷| 亚洲国产精品免费视频| 久久久久亚洲AV成人网| 成人久久免费网站| 亚洲H在线播放在线观看H| 国产高清免费在线| 学生妹亚洲一区二区| 免费a级毛片无码a∨性按摩| 99re6在线精品免费观看| 免费国产在线观看不卡| 成全在线观看免费观看大全 | 国产AV无码专区亚洲AV麻豆丫 | 亚洲丁香婷婷综合久久| 亚洲精品亚洲人成在线观看下载 | 亚洲VA中文字幕无码毛片 | 国产黄色片在线免费观看| 亚洲高清国产拍精品熟女| 亚洲中文字幕久久精品无码喷水| 久久美女网站免费| 亚洲av中文无码乱人伦在线播放| 四虎在线成人免费网站|