亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch17.htm

?? Learn SQL in an easy way...
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD>		<TITLE>Teach Yourself SQL in 21 Days, Second Edition -- Ch 17 -- Using SQL to Generate SQL Statements</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../buttonart/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR><FONT COLOR="#000077">Teach Yourself SQL in 21 Days, Second Edition</FONT></H1></CENTER><CENTER><P><A HREF="../ch16/ch16.htm"><IMG SRC="../buttonart/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch18/ch18.htm"><IMGSRC="../buttonart/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../buttonart/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1><FONT COLOR="#000077">- Day 17 -<BR>Using SQL to Generate SQL Statements</FONT></H1></CENTER><H2><FONT COLOR="#000077">Objectives</FONT></H2><P>Today you learn the concepts behind generating one or more SQL statements froma query. By the end of the day you should understand the following:<UL>	<LI>The benefits of generating SQL statements from a query	<P>	<LI>How to make the output from a query appear in the form of another SQL statement	<P>	<LI>How to use the data dictionary, database tables, or both to form SQL statements</UL><H2><FONT COLOR="#000077">The Purpose of Using SQL to Generate SQL Statements</FONT></H2><P>Generating SQL from another SQL statement simply means writing an SQL statementwhose output forms another SQL statement or command. Until now, all the SQL statementsthat you have learned to write either do something, such as manipulate the data ina table, one row at a time, or produce some kind of report from a query. Today youlearn how to write a query whose output forms another query or SQL statement.</P><P>Why you would ever need to produce an SQL statement from a query? Initially, itis a matter of simplicity and efficiency. You may never need<B> </B>to produce anSQL statement, but without ever doing so you would be ignoring one of SQL's mostpowerful features, one that too many people do not realize exists.</P><P>Generating SQL is rarely mandatory because you can manually create and issue allSQL statements, although the process can be tedious in certain situations. On thesame note generating SQL statements may be necessary when you have a tight deadline.For example, suppose your boss wants to grant access on a new table to all 90 usersin the marketing department (and you want to get home for dinner). Because some usersof this database do not work in marketing, you cannot simply grant access on thetable to public. When you have multiple groups of users with different types of access,you may want to enforce role security, which is a built-in method for controllinguser access to data. In this situation you can create an SQL statement that generates<TT>GRANT</TT> statements to all individuals in the marketing department; that is,it grants each individual the appropriate role(s).</P><P>You will find many situations in which it is advantageous to produce an SQL statementas output to another statement. For example, you might need to execute many similarSQL statements as a group or you might need to regenerate DDL from the data dictionary.When producing SQL as output from another statement, you will always get the datafor your output from either the data dictionary or the schema tables in the database.Figure 17.1 illustrates this procedure.</P><P>As you can see in Figure 17.1, a <TT>SELECT</TT> statement can be issued to thedatabase, drawing its output results either from the data dictionary or from applicationtables in the database. Your statement can arrange the retrieved data into one ormore SQL statements. For instance, if one row is returned, you will have generatedone SQL statement. If 100 rows are returned from your statement, then you will havegenerated 100 SQL statements. When you successfully generate SQL code from the database,you can run that code against the database, which may perform a series of queriesor database actions.</P><P>The remainder of the day is devoted to examples that show you how to produce outputin the form of SQL statements. Most of your information will come from the data dictionary,so you may want to review yesterday's material. (See Day 16, &quot;Using Views toRetrieve Useful Information from the Data Dictionary.&quot;)</P><P><A NAME="01"></A><A HREF="01.htm"><B>Figure 17.1.</B></A></P><P><I>The process of generating SQL from the database.</I></P><BLOCKQUOTE>	<P><HR><BR>	<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Today's examples use Personal Oracle7.	As always, you should apply the concepts discussed today to the syntax of your specific	database implementation. <HR></BLOCKQUOTE><H2><FONT COLOR="#000077">Miscellaneous SQL*Plus Commands</FONT></H2><P>Today's examples use a few new commands. These commands, known as SQL*Plus commands,are specific to Personal Oracle7 and control the format of your output results. (SeeDay 20, &quot;SQL*Plus.&quot;) SQL*Plus commands are issued at the <TT>SQL&gt;</TT>prompt, or they can be used in a file.<BLOCKQUOTE>	<P><HR><FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Although these commands are specific	to Oracle, similar commands are available in other implementations, for example,	Transact-SQL. (Also see Day 19, &quot;Transact-SQL: An Introduction.&quot;) <HR></BLOCKQUOTE><H3><FONT COLOR="#000077">set echo on/off</FONT></H3><P>When you <TT>set echo on</TT>, you will see your SQL statements as they execute.<TT>Set echo off</TT> means that you do not want to see your SQL statements as theyexecute--you just want to see the output.</P><PRE><FONT COLOR="#0066FF">SET ECHO [ ON | OFF ]</FONT></PRE><H3><FONT COLOR="#000077">set feedback on/off</FONT></H3><P>Feedback is the row count of your output. For instance, if you executed a <TT>SELECT</TT>statement that returned 30 rows of data, your feedback would be</P><PRE><FONT COLOR="#0066FF">30 rows selected.</FONT></PRE><P><TT>SET FEEDBACK ON</TT> displays the row count; <TT>SET FEEDBACK OFF</TT> eliminatesthe row count from your output.</P><PRE><FONT COLOR="#0066FF">SET FEEDBACK [ ON | OFF ]</FONT></PRE><H3><FONT COLOR="#000077">set heading on/off</FONT></H3><P>The headings being referred to here are the column headings in the output of a<TT>SELECT</TT> statement, such as <TT>LAST_NAME</TT> or <TT>CUSTOMER_ID</TT>. <TT>SETHEADING ON</TT>, which is the default, displays the column headings of your dataas a part of the output. <TT>SET HEADING OFF</TT>, of course, eliminates the columnheadings from your output.</P><PRE><FONT COLOR="#0066FF">SET HEADING [ ON | OFF ]</FONT></PRE><H3><FONT COLOR="#000077">spool filename/off</FONT></H3><P>Spooling is the process of directing the results of your query to a file. In orderto open a spool file, you enter</P><PRE><FONT COLOR="#0066FF"><B>spool</B> filename</FONT></PRE><P>To close your spool file, you would type</P><PRE><FONT COLOR="#0066FF"><B>spool off</B></FONT></PRE><H4><FONT COLOR="#000077">start <TT>filename</TT></FONT></H4><P>Most SQL commands that we have covered so far have been issued at the <TT>SQL&gt;</TT>prompt. Another method for issuing SQL statements is to create and then execute afile. In SQL*Plus the command to execute an SQL file is <TT>START FILENAME</TT>.</P><PRE><FONT COLOR="#0066FF">START FILENAME</FONT></PRE><H4><FONT COLOR="#000077">ed <TT>filename</TT></FONT></H4><P><TT>ED</TT> is a Personal Oracle7 command that opens a file (existing or file).When you open a file with <TT>ed</TT>, you are using a full-screen editor, whichis often easier than trying to type a lengthy SQL statement at the <TT>SQL&gt;</TT>prompt. You will use this command to modify the contents of your spool file. Youwill find that you use this command often when generating SQL script because youmay have to modify the contents of the file for customization. However, you can achievemost customization through SQL*Plus commands.</P><P><FONT COLOR="#0066FF"><TT>ED FILENAME</TT></FONT><H2><FONT COLOR="#000077">Counting the Rows in All Tables</FONT></H2><P>The first example shows you how to edit your spool file to remove irrelevant linesin your generated code, thus allowing your SQL statement to run without being tarnishedwith syntax errors.<BLOCKQUOTE>	<P><HR><FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Take note of the editing technique	used in this example because we will not show the step in the rest of today's examples.	We assume that you know the basic syntax of SQL statements by now. In addition, you	may choose to edit your spool file in various ways. <HR></BLOCKQUOTE><P>Start by recalling the function to count all rows in a table: <TT>COUNT(*)</TT>.You already know how to select a count on all rows in a single table. For example:</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SELECT COUNT(*)FROM TBL1;</FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">COUNT(*)--------      29</FONT></PRE><P>That technique is handy, but suppose you want to get a row count on all tablesthat you own or that are in your schema. For example, here's a list of the tablesyou own:</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF"><B>SELECT * FROM CAT;</B>TABLE_NAME                     TABLE_TYPE------------------------------ -----------ACCT_PAY                       TABLEACCT_REC                       TABLECUSTOMERS                      TABLEEMPLOYEES                      TABLEHISTORY                        TABLEINVOICES                       TABLEORDERS                         TABLEPRODUCTS                       TABLEPROJECTS                       TABLEVENDORS                        TABLE10 rows selected.</FONT></PRE><H5>ANALYSIS:</H5><P>If you want to get a row count on all your tables, you could manually issue the<TT>COUNT(*)</TT> statement on each table. The feedback would be</P><PRE><FONT COLOR="#0066FF">10 rows selected.</FONT></PRE><P>The following <TT>SELECT</TT> statement creates more <TT>SELECT</TT> statementsto obtain a row count on all the preceding tables.</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>SET ECHO OFF</B>SQL&gt; <B>SET FEEDBACK OFF</B>SQL&gt; <B>SET HEADING OFF</B>SQL&gt; <B>SPOOL CNT.SQL</B>SQL&gt; <B>SELECT 'SELECT COUNT(*) FROM ' || TABLE_NAME || ';'</B>  2  <B>FROM CAT</B>  3  <B>/</B>SELECT COUNT(*) FROM ACCT_PAY;SELECT COUNT(*) FROM ACCT_REC;SELECT COUNT(*) FROM CUSTOMERS;SELECT COUNT(*) FROM EMPLOYEES;SELECT COUNT(*) FROM HISTORY;SELECT COUNT(*) FROM INVOICES;SELECT COUNT(*) FROM ORDERS;SELECT COUNT(*) FROM PRODUCTS;SELECT COUNT(*) FROM PROJECTS;select count(*) FROM VENDORS;</FONT></PRE><H5>ANALYSIS:</H5><P>The first action in the preceding example is to use some SQL*Plus commands. Setting<TT>echo off</TT>, <TT>feedback off</TT>, and <TT>heading off</TT> condenses theoutput to what is actually being selected. Remember, the output is not being usedas a report, but rather as an SQL statement that is ready to be executed. The nextstep is to use the <TT>SPOOL</TT> command to direct the output to a file, which isspecified as <TT>cnt.sql</TT>. The final step is to issue the <TT>SELECT</TT> statement,which will produce output in the form of another statement. Notice the use of singlequotation marks to select a literal string. The combination of single quotation marksand the concatenation (<TT>||</TT>) allows you to combine actual data and literalstrings to form another SQL statement. This example selects its data from the datadictionary. The command <TT>SPOOL OFF</TT> closes the spool file.<BLOCKQUOTE>	<P><HR><FONT COLOR="#000077"><B>TIP:</B></FONT><B> </B>Always edit your output file before	running it to eliminate syntax discrepancies and to further customize the file that	you have created. <HR></P></BLOCKQUOTE><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>SPOOL OFF</B>SQL&gt;<B> ED CNT.SQL</B></FONT></PRE><H5><FONT COLOR="#000000">OUTPUT:</FONT></H5><PRE><FONT COLOR="#0066FF">SQL&gt; SELECT 'SELECT COUNT(*) FROM '||TABLE_NAME||';'  2  FROM CAT;SELECT COUNT(*) FROM ACCT_PAY;SELECT COUNT(*) FROM ACCT_REC;SELECT COUNT(*) FROM CUSTOMERS;SELECT COUNT(*) FROM EMPLOYEES;SELECT COUNT(*) FROM HISTORY;SELECT COUNT(*) FROM INVOICES;SELECT COUNT(*) FROM ORDERS;SELECT COUNT(*) FROM PRODUCTS;SELECT COUNT(*) FROM PROJECTS;SELECT COUNT(*) FROM VENDORS;SQL&gt; SPOOL OFF</FONT></PRE><H5>ANALYSIS:</H5><P>The command <TT>SPOOL OFF</TT> closes the spool file. Then the <TT>ED</TT> commandedits the file. At this point you are inside the file that you created. You shouldremove unnecessary lines from the file, such as the <TT>SELECT</TT> statement, whichwas used to achieve the results, and the <TT>SPOOL OFF</TT> at the end of the file.</P><P>Here is how your file should look after the edit. Notice that each line is a validSQL statement.</P><PRE><FONT COLOR="#0066FF">SELECT COUNT(*) FROM ACCT_PAY;SELECT COUNT(*) FROM ACCT_REC;SELECT COUNT(*) FROM CUSTOMERS;SELECT COUNT(*) FROM EMPLOYEES;SELECT COUNT(*) FROM HISTORY;SELECT COUNT(*) FROM INVOICES;SELECT COUNT(*) FROM ORDERS;SELECT COUNT(*) FROM PRODUCTS;SELECT COUNT(*) FROM PROJECTS;SELECT COUNT(*) FROM VENDORS;</FONT></PRE><P>Now, execute the file:</P><H5>INPUT/OUTPUT:</H5><PRE><FONT COLOR="#0066FF">SQL&gt; <B>SET ECHO ON</B>SQL&gt; <B>SET HEADING ON</B>SQL&gt; <B>START CNT.SQL</B>SQL&gt; SELECT COUNT(*) FROM ACCT_PAY; COUNT(*)---------        7SQL&gt; SELECT COUNT(*) FROM ACCT_REC; COUNT(*)---------        9SQL&gt; SELECT COUNT(*) FROM CUSTOMERS; COUNT(*)---------        5SQL&gt; SELECT COUNT(*) FROM EMPLOYEES; COUNT(*)---------       10SQL&gt; SELECT COUNT(*) FROM HISTORY; COUNT(*)---------       26SQL&gt; SELECT COUNT(*) FROM INVOICES; COUNT(*)---------        0SQL&gt; SELECT COUNT(*) FROM ORDERS; COUNT(*)---------        0SQL&gt; SELECT COUNT(*) FROM PRODUCTS; COUNT(*)---------       10SQL&gt; SELECT COUNT(*) FROM PROJECTS; COUNT(*)---------       16SQL&gt; SELECT COUNT(*) FROM VENDORS; COUNT(*)---------       22SQL&gt;</FONT></PRE><H5>ANALYSIS:</H5><P><TT>Set echo on</TT> enables you to see each statement that was executed. <TT>Setheading on</TT> displays the column heading <TT>COUNT(*)</TT> for each <TT>SELECT</TT>statement. If you had included</P><PRE><FONT COLOR="#0066FF"><B>set feedback on</B></FONT></PRE><P>then</P><PRE><FONT COLOR="#0066FF">1 row selected. </FONT></PRE><P>would have been displayed after each count. This example executed the SQL scriptby using the SQL*Plus <TT>START</TT> command. However, what if you were dealing with50 tables instead of just 10?</P>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品热久久久久夜色精品三区 | 欧美狂野另类xxxxoooo| 欧美一区二区三区视频免费播放| 国产日韩欧美电影| 日韩精品亚洲一区二区三区免费| 成人av电影在线网| 精品国产91洋老外米糕| 亚洲成a人在线观看| 色先锋aa成人| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产精品18久久久| 欧美精品久久一区| 亚洲精品videosex极品| 成人av网站免费观看| 久久亚洲综合色一区二区三区| 亚洲午夜影视影院在线观看| 成人av网站在线| 亚洲国产精品成人综合| 国产最新精品免费| 欧美成人精精品一区二区频| 天天综合日日夜夜精品| 欧美日韩国产精品成人| 一二三四社区欧美黄| 色婷婷av一区| 亚洲精品日产精品乱码不卡| 91蜜桃传媒精品久久久一区二区| 国产精品久久久久久久久动漫 | 亚洲欧美成aⅴ人在线观看| 成人综合在线网站| 国产欧美日韩综合精品一区二区| 国内精品伊人久久久久av影院| 欧美一区欧美二区| 日本最新不卡在线| 欧美成人一区二区三区在线观看| 日韩av中文字幕一区二区| 日韩一区和二区| 免费欧美日韩国产三级电影| 日韩欧美一级二级| 久久99国产精品久久99果冻传媒| 精品999在线播放| 国产真实精品久久二三区| 久久嫩草精品久久久精品一| 国产91精品一区二区麻豆网站| 日本一区二区成人| 色悠悠久久综合| 日韩精品亚洲专区| 久久综合色鬼综合色| 丰满白嫩尤物一区二区| 国产精品白丝在线| 欧美网站一区二区| 日精品一区二区| 欧美精品一区二| www.亚洲色图| 亚洲国产日韩综合久久精品| 欧美喷潮久久久xxxxx| 日本 国产 欧美色综合| 国产亚洲va综合人人澡精品| 91丨porny丨首页| 亚洲成人av一区二区| 久久九九久久九九| 色激情天天射综合网| 日本不卡视频在线| 国产精品美日韩| 在线播放国产精品二区一二区四区| 久久99精品久久久久久国产越南| 国产欧美日韩麻豆91| 在线免费亚洲电影| 久久精品国产精品亚洲红杏| 国产精品丝袜黑色高跟| 欧美理论电影在线| 国产91丝袜在线播放九色| 亚洲人成网站色在线观看| 欧美精品久久一区| 91小视频免费观看| 麻豆一区二区三| 中文字幕在线不卡一区二区三区| 欧美少妇bbb| 成人免费视频一区| 美女诱惑一区二区| 一级女性全黄久久生活片免费| 久久女同性恋中文字幕| 欧美日韩国产a| 99国产精品久| 国产一区二区三区电影在线观看 | 久久精品亚洲精品国产欧美| 欧美亚洲国产一区二区三区va| 国产精品一品视频| 亚洲成av人片一区二区三区| 国产精品国产精品国产专区不蜜 | 国产欧美日韩一区二区三区在线观看| 欧美日本在线视频| 成人av在线播放网址| 国产成人亚洲综合a∨婷婷图片| 日韩电影网1区2区| 亚洲一区二区成人在线观看| 国产精品久久久久久久久图文区 | 亚洲精品成人悠悠色影视| 国产欧美日韩亚州综合| 精品人在线二区三区| 日韩一区二区三区视频| 欧美性感一区二区三区| 99精品久久久久久| 成人动漫一区二区在线| 国产乱子轮精品视频| 久久成人免费网| 免费日本视频一区| 日本少妇一区二区| 日韩电影在线观看一区| 手机精品视频在线观看| 天天综合天天综合色| 日韩高清电影一区| 午夜视频在线观看一区二区 | 亚洲精品综合在线| 亚洲少妇最新在线视频| 国产精品麻豆一区二区| 中文字幕巨乱亚洲| 国产精品成人免费在线| 成人免费小视频| 一区二区三区欧美视频| 一区二区三区四区在线免费观看| 亚洲男帅同性gay1069| 亚洲人成网站精品片在线观看| 亚洲人成网站在线| 一二三区精品福利视频| 亚洲bt欧美bt精品| 日韩二区三区在线观看| 日本在线不卡一区| 午夜天堂影视香蕉久久| 国产白丝精品91爽爽久久| 国产精品一区二区久激情瑜伽| 久久99精品网久久| 国产999精品久久久久久| 9久草视频在线视频精品| 91丨国产丨九色丨pron| 欧美视频中文一区二区三区在线观看| 在线观看不卡视频| 日韩欧美亚洲另类制服综合在线| 久久久久久99精品| 国产日产精品一区| 一卡二卡三卡日韩欧美| 日韩影院免费视频| 精彩视频一区二区| 成人av免费在线播放| 欧洲亚洲精品在线| 精品国产一区二区三区忘忧草| 中文字幕av资源一区| 亚洲综合色网站| 国产一区二区在线观看免费| 96av麻豆蜜桃一区二区| 欧美日韩亚洲综合一区二区三区| 欧美成人伊人久久综合网| 中文字幕一区二区三区四区不卡 | 久久久久国产精品厨房| 最新久久zyz资源站| 日本麻豆一区二区三区视频| 国产suv精品一区二区883| 欧美日韩一区二区三区高清| 久久综合九色综合97婷婷| 亚洲欧美一区二区不卡| 久久99精品国产| 在线亚洲免费视频| 国产欧美视频一区二区三区| 亚洲成av人影院| 成人午夜电影久久影院| 欧美一区永久视频免费观看| 日韩伦理电影网| 精品亚洲aⅴ乱码一区二区三区| 色综合夜色一区| 久久久综合精品| 免费一级片91| 在线观看亚洲精品| 国产精品伦一区二区三级视频| 奇米色777欧美一区二区| 色婷婷国产精品| 欧美极品少妇xxxxⅹ高跟鞋 | 欧美日韩一级二级三级| 久久综合久久综合亚洲| 亚洲成人资源网| 不卡的av在线播放| 久久免费国产精品| 免费一级欧美片在线观看| 91福利在线看| 美女在线观看视频一区二区| 欧美午夜精品电影| 一区二区在线观看免费视频播放| 国产一区91精品张津瑜| 日韩欧美美女一区二区三区| 亚洲综合在线观看视频| 99精品在线观看视频| 国产日韩亚洲欧美综合| 狠狠色综合播放一区二区| 91精品国产综合久久久久久| 亚洲一区在线播放| 在线观看欧美精品| 亚洲一区二区三区四区在线免费观看| 97se亚洲国产综合自在线 | 成人高清视频在线观看| 国产亚洲一区二区三区在线观看| 久久精品久久精品| 精品国产乱码久久久久久老虎|