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

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

?? ch19.htm

?? Learn SQL in an easy way...
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
operations.<H4><FONT COLOR="#000077">Using Variables to Store Data</FONT></H4><P>Variables are available only within the current statement block. To execute ablock of statements using the Transact-SQL language, the <TT>go</TT> statement isexecuted. (Oracle uses the semicolon for the same purpose.) The scope of a variablerefers to the usage of the variable within the current Transact-SQL statement.</P><P>You cannot initialize variables simply by using the <TT>=</TT> sign. Try the followingstatement and note that an error will be returned.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @name char(30)</B>2&gt; <B>@name = &quot;Billy Brewster&quot;</B>3&gt;<B> go</B></FONT></PRE><P>You should have received an error informing you of the improper syntax used inline 2. The proper way to initialize a variable is to use the <TT>SELECT</TT> command.(Yes, the same command you have already mastered.) Repeat the preceding example usingthe correct syntax:</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @name char(30)</B>2&gt; <B>select @name = &quot;Billy Brewster&quot;</B>3&gt; <B>go</B></FONT></PRE><P>This statement was executed correctly, and if you had inserted additional statementsbefore executing the <TT>go</TT> statement, the <TT>@name</TT> variable could havebeen used.<H4><FONT COLOR="#000077">Retrieving Data into Local Variables</FONT></H4><P>Variables often store data that has been retrieved from the database. They canbe used with common SQL commands, such as <TT>SELECT</TT>, <TT>INSERT</TT>, <TT>UPDATE</TT>,and <TT>DELETE</TT>. Example 19.1 illustrates the use of variables in this manner.<H4><FONT COLOR="#000077">Example 19.1</FONT></H4><P>This example retrieves the name of the player in the <TT>BASEBALL</TT> databasewho has the highest batting average and plays for the Portland Beavers.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @team_id int, @player_name char(30), @max_avg float</B>2&gt; <B>select @team_id = TEAM_ID from TEAMS where CITY = &quot;Portland&quot;</B>3&gt; <B>select @max_avg = max(AVERAGE) from BATTERS where TEAM = @team_id</B>4&gt; <B>select @player_name = NAME from BATTERS where AVERAGE = @max_avg</B>5&gt; <B>go</B></FONT></PRE><H5>ANALYSIS:</H5><P>This example was broken down into three queries to illustrate the use of variables.<H3><FONT COLOR="#000077">The PRINT Command</FONT></H3><P>One other useful feature of Transact-SQL is the <TT>PRINT</TT> command that enablesyou to print output to the display device. This command has the following syntax:</P><H5>SYNTAX:</H5><PRE><FONT COLOR="#0066FF">PRINT character_string</FONT></PRE><P>Although <TT>PRINT</TT> displays only character strings, Transact-SQL providesa number of useful functions that can convert different data types to strings (andvice versa).<H4><FONT COLOR="#000077">Example 19.2</FONT></H4><P>Example 19.2 repeats Example 19.1 but prints the player's name at the end.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @team_id int, @player_name char(30), @max_avg float</B>2&gt; <B>select @team_id = TEAM_ID from TEAMS where CITY = &quot;Portland&quot;</B>3&gt; <B>select @max_avg = max(AVERAGE) from BATTERS where TEAM = @team_id</B>4&gt; <B>select @player_name = NAME from BATTERS where AVERAGE = @max_avg</B>5&gt; <B>print @player_name</B>6&gt; <B>go</B></FONT></PRE><P>Note that a variable can be used within a <TT>WHERE</TT> clause (or any otherclause) just as if it were a constant value.<H2><FONT COLOR="#000077">Flow Control</FONT></H2><P>Probably the most powerful set of Transact-SQL features involves its capabilityto control program flow. If you have programmed with other popular languages suchas C, COBOL, Pascal, and Visual Basic, then you are probably already familiar withcontrol commands such as <TT>IF...THEN</TT> statements and loops. This section containssome of the major commands that allow you to enforce program flow control.<H3><FONT COLOR="#000077">BEGIN and END Statements</FONT></H3><P>Transact-SQL uses the <TT>BEGIN</TT> and <TT>END</TT> statements to signify thebeginning and ending points of blocks of code. Other languages use brackets (<TT>{}</TT>)or some other operator to signify the beginning and ending points of functional groupsof code. These statements are often combined with <TT>IF...ELSE</TT> statements and<TT>WHILE</TT> loops. Here is a sample block using <TT>BEGIN</TT> and <TT>END</TT>:</P><H5>SYNTAX:</H5><PRE><FONT COLOR="#0066FF">BEGIN  statement1  statement2  statement3...END</FONT></PRE><H3><FONT COLOR="#000077">IF...ELSE Statements</FONT></H3><P>One of the most basic programming constructs is the <TT>IF...ELSE</TT> statement.Nearly every programming language supports this construct, and it is extremely usefulfor checking the value of data retrieved from the database. The Transact-SQL syntaxfor the <TT>IF...ELSE</TT> statement looks like this:</P><H5>SYNTAX:</H5><PRE><FONT COLOR="#0066FF">if (condition)begin     (statement block)endelse if (condition)begin     statement block)end...elsebegin     (statement block)end</FONT></PRE><P>Note that for each condition that might be true, a new <TT>BEGIN/END</TT> blockof statements was entered. Also, it is considered good programming practice to indentstatement blocks a set amount of spaces and to keep this number of spaces the samethroughout your application. This visual convention greatly improves the readabilityof the program and cuts down on silly errors that are often caused by simply misreadingthe code.<H4><FONT COLOR="#000077">Example 19.3</FONT></H4><P>Example 19.3 extends Example 19.2 by checking the player's batting average. Ifthe player's average is over .300, the owner wants to give him a raise. Otherwise,the owner could really care less about the player!</P><P>Example 19.3 uses the <TT>IF...ELSE</TT> statement to evaluate conditions withinthe statement. If the first condition is <TT>true</TT>, then specified text is printed;alternative text is printed under any other conditions (<TT>ELSE</TT>).</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @team_id int, @player_name char(30), @max_avg float</B>2&gt; <B>select @team_id = TEAM_ID from TEAMS where CITY = &quot;Portland&quot;</B>3&gt; <B>select @max_avg = max(AVERAGE) from BATTERS where TEAM = @team_id</B>4&gt; <B>select @player_name = NAME from BATTERS where AVERAGE = @max_avg</B>5&gt; <B>if (@max_avg &gt; .300)</B>6&gt; <B>begin</B>7&gt;     <B> print @player_name</B>8&gt;     <B> print &quot;Give this guy a raise!&quot;</B>9&gt; <B>end</B>10&gt; <B>else</B>11&gt; <B>begin</B>12&gt;     <B> print @player_name</B>13&gt;      <B>print &quot;Come back when you're hitting better!&quot;</B>14&gt; <B>end</B>15&gt;<B> go</B></FONT></PRE><H4><FONT COLOR="#000077">Example 19.4</FONT></H4><P>This new <TT>IF</TT> statement enables you to add some programming logic to thesimple <TT>BASEBALL</TT> database queries. Example 19.4 adds an <TT>IF...ELSE IF...ELSE</TT>branch to the code in Ex- ample 19.3.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @team_id int, @player_name char(30), @max_avg float</B>2&gt;<B> select @team_id = TEAM_ID from TEAMS where CITY = &quot;Portland&quot;</B>3&gt; <B>select @max_avg = max(AVERAGE) from BATTERS where TEAM = @team_id</B>4&gt; <B>select @player_name = NAME from BATTERS where AVERAGE = @max_avg</B>5&gt; <B>if (@max_avg &gt; .300)</B>6&gt; <B>begin</B>7&gt;     <B> print @player_name</B>8&gt;    <B>  print &quot;Give this guy a raise!&quot;</B>9&gt; <B>end</B>10&gt; <B>else if (@max_avg &gt; .275)</B>11&gt; <B>begin</B>12&gt;     <B>print @player_name</B>13&gt;    <B> print &quot;Not bad.  Here's a bonus!&quot;</B>14&gt; <B>end</B>15&gt; <B>else</B>16&gt;<B> begin</B>17&gt;      <B>print @player_name</B>18&gt;      <B>print &quot;Come back when you're hitting better!&quot;</B>19&gt; <B>end</B>20&gt;<B> go</B></FONT></PRE><P>Transact-SQL also enables you to check for a condition associated with an <TT>IF</TT>statement. These functions can test for certain conditions or values. If the functionreturns <TT>TRUE</TT>, the <TT>IF</TT> branch is executed. Otherwise, if provided,the <TT>ELSE</TT> branch is executed, as you saw in the previous example.<H3><FONT COLOR="#000077">The EXISTS Condition</FONT></H3><P>The <TT>EXISTS</TT> keyword ensures that a value is returned from a <TT>SELECT</TT>statement. If a value is returned, the <TT>IF</TT> statement is executed. Example19.5 illustrates this logic.<H4><FONT COLOR="#000077">Example 19.5</FONT></H4><P>In this example the <TT>EXISTS</TT> keyword evaluates a condition in the <TT>IF</TT>.The condition is specified by using a <TT>SELECT</TT> statement.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt;<B> if exists (select * from TEAMS where TEAM_ID &gt; 5)</B>2&gt; <B>begin</B>3&gt;     <B> print &quot;IT EXISTS!!&quot;</B>4&gt; <B>end</B>5&gt; <B>else</B>6&gt;<B> begin</B>7&gt;     <B> print &quot;NO ESTA AQUI!&quot;</B>8&gt; <B>end</B></FONT></PRE><H3><FONT COLOR="#000077">Testing a Query's Result</FONT></H3><P>The <TT>IF</TT> statement can also test the result returned from a <TT>SELECT</TT>query. Example 19.6 implements this feature to check for the maximum batting averageamong players.<H4><FONT COLOR="#000077">Example 19.6</FONT></H4><P>This example is similar to Example 19.5 in that it uses the <TT>SELECT</TT> statementto define a condition. This time, however, we are testing the condition with thegreater than sign (<TT>&gt;</TT>).</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>if (select max(AVG) from BATTERS) &gt; .400</B>2&gt; <B>begin</B>3&gt;      <B>print &quot;UNBELIEVABLE!!&quot;</B>4&gt; <B>end</B>5&gt; <B>else</B>6&gt;     <B> print &quot;TED WILLIAMS IS GETTING LONELY!&quot;</B>7&gt; <B>end</B></FONT></PRE><P>We recommend experimenting with your SQL implementation's <TT>IF</TT> statement.Think of several conditions you would be interested in checking in the <TT>BASEBALL</TT>(or any other) database. Run some queries making use of the <TT>IF</TT> statementto familiarize yourself with its use.<H3><FONT COLOR="#000077">The WHILE Loop</FONT></H3><P>Another popular programming construct that Transact-SQL supports is the <TT>WHILE</TT>loop. This command has the following syntax:</P><H5>SYNTAX:</H5><PRE><FONT COLOR="#0066FF">WHILE logical_expression     statement(s)</FONT></PRE><H4><FONT COLOR="#000077">Example 19.7</FONT></H4><P>The <TT>WHILE</TT> loop continues to loop through its statements until the logicalexpression it is checking returns a <TT>FALSE</TT>. This example uses a simple <TT>WHILE</TT>loop to increment a local variable (named <TT>COUNT</TT>).</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @COUNT int</B>2&gt; <B>select @COUNT = 1</B>3&gt; <B>while (@COUNT &lt; 10)</B>4&gt; <B>begin</B>5&gt;      <B>select @COUNT = @COUNT + 1</B>6&gt;     <B> print &quot;LOOP AGAIN!&quot;</B>7&gt;<B> end</B>8&gt; <B>print &quot;LOOP FINISHED!&quot;</B></FONT></PRE><BLOCKQUOTE>	<P><HR><FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Example 19.7 implements a simple	<TT>FOR</TT> loop. Other implementations of SQL, such as Oracle's PL/SQL, actually	provide a <TT>FOR</TT> loop statement. Check your documentation to determine whether	the system you are using supports this useful command. <HR></BLOCKQUOTE><H3><FONT COLOR="#000077">The BREAK Command</FONT></H3><P>You can issue the <TT>BREAK</TT> command within a <TT>WHILE</TT> loop to forcean immediate exit from the loop. The <TT>BREAK</TT> command is often used along withan <TT>IF</TT> test to check some condition. If the condition check succeeds, youcan use the <TT>BREAK</TT> command to exit from the <TT>WHILE</TT> loop. Commandsimmediately following the <TT>END</TT> command are then executed. Example 19.8 illustratesa simple use of the <TT>BREAK</TT> command. It checks for some arbitrary number (say<TT>@COUNT = 8</TT>). When this condition is met, it breaks out of the <TT>WHILE</TT>loop.<H4><FONT COLOR="#000077">Example 19.8</FONT></H4><P>Notice the placement of the <TT>BREAK</TT> statement after the evaluation of thefirst condition in the <TT>IF</TT>.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @COUNT int</B>2&gt; <B>select @COUNT = 1</B>3&gt; <B>while (@COUNT &lt; 10)</B>4&gt; <B>begin</B>5&gt;      <B>select @COUNT = @COUNT + 1</B>6&gt;     <B> if (@COUNT = 8)</B>7&gt;     <B> begin</B>8&gt;           <B> break</B>9&gt;    <B>  end</B>10&gt;    <B> else</B>11&gt;    <B> begin</B>12&gt;           <B>print &quot;LOOP AGAIN!&quot;</B>13&gt;     <B>end</B>14&gt; <B>end</B>15&gt;<B> print &quot;LOOP FINISHED!&quot;</B></FONT></PRE><H5>ANALYSIS:</H5><P>The <TT>BREAK</TT> command caused the loop to be exited when the <TT>@COUNT</TT>variable equaled <TT>8</TT>.<H3><FONT COLOR="#000077">The CONTINUE Command</FONT></H3><P>The <TT>CONTINUE</TT> command is also a special command that can be executed fromwithin a <TT>WHILE</TT> loop. The <TT>CONTINUE</TT> command forces the loop to immediatelyjump back to the beginning, rather than executing the remainder of the loop and thenjumping back to the beginning. Like the <TT>BREAK</TT> command, the <TT>CONTINUE</TT>command is often used with an <TT>IF</TT> statement to check for some condition andthen force an action, as shown in Example 19.9.<H4><FONT COLOR="#000077">Example 19.9</FONT></H4><P>Notice the placement of the <TT>CONTINUE</TT> statement after the evaluation ofthe first condition in the <TT>IF</TT>.</P><H5>INPUT:</H5><PRE><FONT COLOR="#0066FF">1&gt; <B>declare @COUNT int</B>2&gt; <B>select @COUNT = 1</B>3&gt; <B>while (@COUNT &lt; 10)</B>4&gt; <B>begin</B>5&gt;     <B> select @COUNT = @COUNT + 1</B>6&gt;     <B> if (@COUNT = 8)</B>7&gt;  <B>    begin</B>8&gt;        <B>    continue</B>9&gt;     <B> end</B>10&gt;     <B>else</B>11&gt;     <B>begin</B>12&gt;          <B> print &quot;LOOP AGAIN!&quot;</B>13&gt;    <B> end</B>14&gt; <B>end</B>15&gt; <B>print &quot;LOOP FINISHED!&quot;</B></FONT></PRE><H5>ANALYSIS:</H5><P>Example 19.9 is identical to Example 19.8 except that the <TT>CONTINUE</TT> commandreplaces the <TT>BREAK</TT> command. Now instead of exiting the loop when <TT>@COUNT= 8</TT>, it simply jumps back to the top of the <TT>WHILE</TT> statement and continues.<H3><FONT COLOR="#000077">Using the WHILE Loop to Scroll Through a Table</FONT></H3><P>SQL Server and many other database systems have a special type of object--thecursor--that enables you to scroll through a table's records one record at a time.(Refer to Day 13.) However, some database systems (including SQL Server pre-System

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
美女一区二区在线观看| 国产成人免费xxxxxxxx| 91在线视频播放| 欧美国产成人精品| k8久久久一区二区三区| 国产日韩欧美电影| 99热这里都是精品| 中文字幕一区二区三区四区不卡| 99久久99久久精品免费看蜜桃| 国产精品女上位| 欧美另类高清zo欧美| 精品中文字幕一区二区小辣椒| 久久精品日产第一区二区三区高清版 | 亚洲欧洲中文日韩久久av乱码| 国产成人午夜精品影院观看视频| 中文字幕国产精品一区二区| 成人黄色国产精品网站大全在线免费观看| 国产亚洲福利社区一区| 99九九99九九九视频精品| 性做久久久久久免费观看| 中文字幕中文字幕一区| 狠狠色狠狠色合久久伊人| 中文字幕欧美日本乱码一线二线| 色偷偷久久人人79超碰人人澡| 日产精品久久久久久久性色| 国产精品久久久爽爽爽麻豆色哟哟| 日本精品视频一区二区| 久久精品国产精品亚洲精品| 中文字幕在线观看不卡| 日韩视频在线你懂得| 91视频精品在这里| 国产成人av影院| 麻豆91免费观看| 亚洲超碰精品一区二区| 136国产福利精品导航| 精品国产一区二区三区四区四 | 色欲综合视频天天天| 久久99精品久久久久久动态图 | 国内精品伊人久久久久av影院| 亚洲天堂免费看| 国产精品久久久久久久浪潮网站| 91精品国产综合久久福利| 欧美丝袜自拍制服另类| 91在线视频播放地址| aa级大片欧美| 99视频精品全部免费在线| 99久久免费精品| 在线观看91视频| 欧美日韩成人综合| 3751色影院一区二区三区| 欧美精品粉嫩高潮一区二区| 欧美高清精品3d| 欧美不卡一区二区三区| 日韩女同互慰一区二区| 欧美一区二区三区视频免费| 欧美亚洲国产一区二区三区va| 91日韩在线专区| 在线中文字幕一区| 91国产视频在线观看| 色播五月激情综合网| 91亚洲精品久久久蜜桃| 在线视频国内自拍亚洲视频| 91一区二区在线| 欧美日韩国产色站一区二区三区| 国产成人午夜视频| 91丨porny丨在线| 波波电影院一区二区三区| www.av精品| 成人激情黄色小说| 日本精品免费观看高清观看| 6080国产精品一区二区| 日韩美女一区二区三区| 日韩一区二区电影| 亚洲国产精品成人综合色在线婷婷 | 在线免费不卡电影| 欧美大白屁股肥臀xxxxxx| 久久久久久久综合狠狠综合| 综合在线观看色| 日韩电影在线免费| 国产不卡在线一区| 538在线一区二区精品国产| 欧美精品一区二区三区很污很色的| 国产精品视频免费| 久久精品国产一区二区三区免费看| 福利视频网站一区二区三区| 91久久免费观看| 久久精品亚洲精品国产欧美| 香蕉加勒比综合久久| 国产福利一区二区三区| 欧美日韩www| 亚洲美女少妇撒尿| 99久久国产综合精品色伊| 欧美日韩一区二区三区视频 | 91国产免费观看| 久久久一区二区| 青草av.久久免费一区| 成人小视频免费在线观看| 日韩亚洲欧美高清| 亚洲a一区二区| 欧美亚洲愉拍一区二区| 亚洲欧洲综合另类在线| 91色婷婷久久久久合中文| 国产精品天天看| 成人丝袜高跟foot| 亚洲国产高清在线观看视频| 国产大陆a不卡| 久久久久久久久久久久久女国产乱 | 99久久久无码国产精品| 国产精品福利一区二区| 99久久777色| 亚洲国产精品久久久久婷婷884| 在线免费不卡视频| 五月天视频一区| 欧美日韩一区二区三区四区| 精油按摩中文字幕久久| 久久人人97超碰com| 成a人片国产精品| 亚洲亚洲精品在线观看| 日韩三级视频中文字幕| 国产成人精品亚洲777人妖| 91论坛在线播放| 亚洲午夜激情网站| 精品国产伦一区二区三区观看方式| 国产乱淫av一区二区三区 | 青青草97国产精品免费观看 | 亚洲国产一区在线观看| 欧美成人激情免费网| www.亚洲色图| 欧美bbbbb| www一区二区| 精品视频一区二区三区免费| 国产一区二区三区久久久| 中文字幕亚洲综合久久菠萝蜜| 91精品国产色综合久久久蜜香臀| 国产.精品.日韩.另类.中文.在线.播放| 欧美高清在线一区二区| 欧美不卡激情三级在线观看| 在线视频观看一区| 欧美性猛片xxxx免费看久爱| 国产suv精品一区二区三区| 午夜精品一区二区三区电影天堂 | 99精品视频一区二区| 精品午夜久久福利影院| 午夜a成v人精品| 亚洲大片一区二区三区| 亚洲欧美成aⅴ人在线观看 | 亚洲成av人**亚洲成av**| 亚洲精品视频在线观看免费| 国产午夜精品一区二区三区视频 | 久久91精品国产91久久小草| 一区二区三区在线不卡| 国产精品麻豆久久久| 欧美精品一区二区三区高清aⅴ | 国模少妇一区二区三区| 肉色丝袜一区二区| 久久99精品视频| 国产99久久精品| www.激情成人| 日本精品一区二区三区高清 | 欧美tk—视频vk| 精品少妇一区二区三区免费观看| 日韩欧美你懂的| 国产亚洲欧美一区在线观看| 日韩女优av电影在线观看| 国产欧美日韩另类视频免费观看 | 成人国产亚洲欧美成人综合网| 精品视频1区2区| 综合自拍亚洲综合图不卡区| 精品视频1区2区3区| 欧美成人免费网站| 又紧又大又爽精品一区二区| 蜜臀久久久99精品久久久久久| 高清久久久久久| 久久先锋影音av鲁色资源网| 一区二区国产视频| 不卡的电影网站| 精品久久国产老人久久综合| 亚洲国产综合91精品麻豆| 国产馆精品极品| 日韩一区二区视频| 亚洲国产视频一区| 91国偷自产一区二区开放时间 | 日韩精品资源二区在线| 亚洲大片免费看| 91豆麻精品91久久久久久| 1024亚洲合集| 色综合天天性综合| 亚洲免费看黄网站| 一本一本久久a久久精品综合麻豆| 日本一区二区免费在线观看视频 | 日韩电影在线观看电影| 欧美日韩视频专区在线播放| 亚洲一区av在线| 欧美群妇大交群的观看方式| 亚洲宅男天堂在线观看无病毒| 在线观看亚洲专区| 天天综合网天天综合色| 91精品国产全国免费观看| 日韩成人一级片| 久久噜噜亚洲综合|