⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch20.htm

📁 Learn SQL in an easy way...
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">appinfo is ON and set to &quot;SQL*Plus&quot;arraysize 15autocommit OFFautoprint OFFautotrace OFFblockterminator &quot;.&quot; (hex 2e)btitle OFF and is the 1st few characters of the next SELECT statementclosecursor OFFcolsep &quot; &quot;cmdsep OFFcompatibility version NATIVEconcat &quot;.&quot; (hex 2e)copycommit 0copytypecheck is ONcrt &quot;&quot;define &quot;&amp;&quot; (hex 26)echo OFFeditfile &quot;afiedt.buf&quot;embedded OFFescape OFFfeedback ON for 6 or more rowsflagger OFFflush ONheading ONheadsep &quot;|&quot; (hex 7c)linesize 100lno 6long 80longchunksize 80maxdata 60000newpage 1null &quot;&quot;numformat &quot;&quot;numwidth 9pagesize 24pause is OFFpno 1recsep WRAPrecsepchar &quot; &quot; (hex 20)release 703020200repheader OFF and is NULLrepfooter OFF and is NULLserveroutput OFFshowmode OFFspool OFFsqlcase MIXEDsqlcode 1007sqlcontinue &quot;&gt; &quot;sqlnumber ONsqlprefix &quot;#&quot; (hex 23)sqlprompt &quot;SQL&gt; &quot;sqlterminator &quot;;&quot; (hex 3b)suffix &quot;SQL&quot;tab ONtermout ONtime OFFtiming OFFtrimout ONtrimspool OFFttitle OFF and is the 1st few characters of the next SELECT statementunderline &quot;-&quot; (hex 2d)user is &quot;RYAN&quot;verify ONwrap : lines will be wrapped</FONT></PRE><P>The <TT>SHOW </TT>command displays a specific setting entered by the user. Supposeyou have access to multiple database user IDs and you want to see how you are loggedon. You can issue the following command:</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>show user</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">user is &quot;RYAN&quot;</FONT></PRE><P>To see the current line size of output, you would type:</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>show linesize</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#000000"></FONT></PRE><PRE><FONT COLOR="#0066FF">linesize 100</FONT></PRE><H2><FONT COLOR="#000077">File Commands</FONT></H2><P>Various commands enable you to manipulate files in SQL*Plus. These commands includecreating a file, editing the file using a full-screen editor as opposed to usingthe SQL*Plus buffer, and redirecting output to a file. You also need to know howto execute an SQL file after it is created.<H3><FONT COLOR="#000077">The SAVE, GET, and EDIT Commands</FONT></H3><P>The <TT>SAVE</TT> command saves the contents of the SQL statement in the bufferto a file whose name you specify. For example:</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>select *</B>  2  <B>from products</B>  3  <B>where unit_cost &lt; 25</B></FONT></PRE><PRE><FONT COLOR="#0066FF">SQL&gt; <B>save query1.sql</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">Created file query1.sql</FONT></PRE><H5>ANALYSIS:</H5><P>After a file has been saved, you can use the <TT>GET</TT> command to list thefile. <TT>GET</TT> is very similar to the <TT>LIST</TT> command. Just remember that<TT>GET</TT> deals with statements that have been saved to files, whereas <TT>LIST</TT>deals with the statement that is stored in the buffer.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt;<B> get query1</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">  1  select *  2  from products  3* where unit_cost &lt; 25</FONT></PRE><P>You can use the <TT>EDIT</TT> command either to create a new file or to edit anexisting file. When issuing this command, you are taken into a full-screen editor,more than likely Notepad in Windows. You will find that it is usually easier to modifya file with <TT>EDIT</TT> than through the buffer, particularly if you are dealingwith a large or complex statement. Figure 20.1 shows an example of the <TT>EDIT</TT>command.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>edit query1.sql</B></FONT></PRE><P><A NAME="01"></A><A HREF="01.htm"><B>Figure 20.1.<BR></B></A><I>Editing a file in SQL*Plus.</I></P><H3><FONT COLOR="#000077">Starting a File</FONT></H3><P>Now that you know how to create and edit an SQL file, the command to execute itis simple. It can take one of the following forms:</P><H5>SYNTAX:</H5><PRE><FONT COLOR="#0066FF">START filename</FONT></PRE><P>or</P><PRE><FONT COLOR="#0066FF">STA filename</FONT></PRE><P>or</P><PRE><FONT COLOR="#0066FF">@filename</FONT></PRE><BLOCKQUOTE>	<P><HR><FONT COLOR="#000077"><B>TIP:</B></FONT><B> </B>Commands are not case sensitive.	<HR></P></BLOCKQUOTE><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>start query1.sql</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">PRO PRODUCT_NAME                   UNIT_COST--- ------------------------------ ---------P02 NO 2 PENCILS - 20 PACK              1.99P03 COFFEE MUG                          6.95P04 FAR SIDE CALENDAR                   10.5P05 NATURE CALENDAR                    12.99</FONT></PRE><BLOCKQUOTE>	<P><HR><FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>You do not have to specify the file	extension <TT>.sql</TT> to start a file from SQL*Plus. The database assumes that	the file you are executing has this extension. Similarly, when you are creating a	file from the <TT>SQL&gt;</TT> prompt or use <TT>SAVE</TT>, <TT>GET</TT>, or <TT>EDIT</TT>,	you do not have to include the extension if it is <TT>.sql</TT>. <HR></P></BLOCKQUOTE><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt;<B> @query1</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">PRO PRODUCT_NAME                   UNIT_COST--- ------------------------------ ---------P02 NO 2 PENCILS - 20 PACK              1.99P03 COFFEE MUG                          6.95P04 FAR SIDE CALENDAR                  10.5P05 NATURE CALENDAR                    12.99</FONT></PRE><H5><FONT COLOR="#000000">INPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>run query1</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">  1  select *  2  from products  3* where unit_cost &lt; 25PRO PRODUCT_NAME                   UNIT_COST--- ------------------------------ ---------P02 NO 2 PENCILS - 20 PACK              1.99P03 COFFEE MUG                          6.95P04 FAR SIDE CALENDAR                   10.5P05 NATURE CALENDAR                    12.99</FONT></PRE><P>Notice that when you use <TT>RUN</TT> to execute a query, the statement is echoed,or displayed on the screen.<H3><FONT COLOR="#000077">Spooling Query Output</FONT></H3><P>Viewing the output of your query on the screen is very convenient, but what ifyou want to save the results for future reference or you want to print the file?The <TT>SPOOL</TT> command allows you to send your output to a specified file. Ifthe file does not exist, it will be created. If the file exists, it will be overwritten,as shown in Figure 20.2.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>spool prod.lst</B>SQL&gt; <B>select *</B>  2  <B>from products;</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">PRO PRODUCT_NAME                   UNIT_COST--- ------------------------------ --------- P01 MICKEY MOUSE LAMP                  29.95P02 NO 2 PENCILS - 20 PACK              1.99P03 COFFEE MUG                          6.95P04 FAR SIDE CALENDAR                   10.5P05 NATURE CALENDAR                    12.99P06 SQL COMMAND REFERENCE              29.99P07 BLACK LEATHER BRIEFCASE            99.997 rows selected.</FONT></PRE><H5><FONT COLOR="#000000">INPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>spool off</B>SQL&gt; <B>edit prod.lst</B></FONT></PRE><H5>ANALYSIS:</H5><P>The output in Figure 20.2 is an SQL*Plus file. You must use the <TT>SPOOL OFF</TT>command to stop spooling to a file. When you exit SQL*Plus, <TT>SPOOL OFF</TT> isautomatic. But if you do not exit and you continue to work in SQL*Plus, everythingyou do will be spooled to your file until you issue the command <TT>SPOOL OFF</TT>.</P><P><A NAME="02"></A><A HREF="02.htm"><B>Figure 20.2.<BR></B></A><I>Spooling your output to a file.</I></P><H2><FONT COLOR="#000077">SET Commands</FONT></H2><P><TT>SET</TT> commands in Oracle change SQL*Plus session settings. By using thesecommands, you can customize your SQL working environment and invoke options to makeyour output results more presentable. You can control many of the <TT>SET</TT> commandsby turning an option on or off.</P><P>To see how the <TT>SET</TT> commands work, perform a simple <TT>select</TT>:</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>select *</B>  2  <B>from products;</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">PRO PRODUCT_NAME                   UNIT_COST--- ------------------------------ --------- P01 MICKEY MOUSE LAMP                  29.95P02 NO 2 PENCILS - 20 PACK              1.99P03 COFFEE MUG                          6.95P04 FAR SIDE CALENDAR                   10.5P05 NATURE CALENDAR                    12.99P06 SQL COMMAND REFERENCE              29.99P07 BLACK LEATHER BRIEFCASE            99.997 rows selected.</FONT></PRE><H5>ANALYSIS:</H5><P>The last line of output</P><PRE><FONT COLOR="#0066FF">7 rows selected.</FONT></PRE><P>is called feedback, which is an SQL setting that can be modified. The settingshave defaults, and in this case the default for <TT>FEEDBACK</TT> is <TT>on</TT>.If you wanted, you could type</P><PRE><FONT COLOR="#0066FF">SET FEEDBACK ON</FONT></PRE><P>before issuing your select statement. Now suppose that you do not want to seethe feedback, as happens to be the case with some reports, particularly summarizedreports with computations.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>set feedback off</B>SQL&gt; <B>select *</B>  2  <B>from products;</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">PRO PRODUCT_NAME                   UNIT_COST--- ------------------------------ ---------P01 MICKEY MOUSE LAMP                  29.95P02 NO 2 PENCILS - 20 PACK              1.99P03 COFFEE MUG                          6.95P04 FAR SIDE CALENDAR                   10.5P05 NATURE CALENDAR                    12.99P06 SQL COMMAND REFERENCE              29.99P07 BLACK LEATHER BRIEFCASE            99.99</FONT></PRE><H5>ANALYSIS:</H5><P><TT>SET FEEDBACK OFF</TT> turns off the feedback display.</P><P>In some cases you may want to suppress the column headings from being displayedon a report. This setting is called <TT>HEADING</TT>, which can also be set <TT>ON</TT>or <TT>OFF</TT>.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>set heading off</B>SQL&gt;<B> /</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">P01 MICKEY MOUSE LAMP                  29.95P02 NO 2 PENCILS - 20 PACK              1.99P03 COFFEE MUG                          6.95P04 FAR SIDE CALENDAR                   10.5P05 NATURE CALENDAR                    12.99P06 SQL COMMAND REFERENCE              29.99P07 BLACK LEATHER BRIEFCASE            99.99</FONT></PRE><H5>ANALYSIS:</H5><P>The column headings have been eliminated from the output. Only the actual datais displayed.</P><P>You can change a wide array of settings to manipulate how your output is displayed.One option, <TT>LINESIZE</TT>, allows you to specify the length of each line of youroutput. A small line size will more than likely cause your output to wrap; increasingthe line size may be necessary to suppress wrapping of a line that exceeds the default

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -