uTools-Manuals/docs/sql/MID() 函数.html
2019-05-07 10:15:08 +08:00

31 lines
2.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="m-bg">
<h1>SQL MID() 函数</h1>
<h2>MID() 函数</h2> <p>MID() 函数用于从文本字段中提取字符。</p> <h3>SQL MID() 语法</h3> <div class="code notranslate"><pre><code class="language-sql"><div> SELECT MID(column_name,start[,length]) FROM table_name;</div></code></pre></div> <br/><table class="reference notranslate">
<tr>
<th align="left" valign="top" width="20%">参数</th> <th align="left" valign="top" width="80%">描述</th> </tr>
<tr>
<td valign="top">column_name</td> <td valign="top">必需。要提取字符的字段。</td> </tr>
<tr>
<td valign="top">start</td> <td valign="top">必需。规定开始位置(起始值是 1</td> </tr>
<tr>
<td valign="top">length</td> <td valign="top">可选。要返回的字符数。如果省略,则 MID() 函数返回剩余文本。</td> </tr>
</table>
<h2>演示数据库</h2> <p>在本教程中,我们将使用众所周知的 Northwind 样本数据库。</p> <p>下面是选自 "Customers" 表的数据:</p> <table class="reference notranslate">
<tr>
<th>CustomerID</th> <th>CustomerName</th> <th>ContactName</th> <th>Address</th> <th>City</th> <th>PostalCode</th> <th>Country</th> </tr>
<tr>
<td>1<br/><br/>
</td> <td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Obere Str. 57</td> <td>Berlin</td> <td>12209</td> <td>Germany</td> </tr>
<tr>
<td>2</td> <td>Ana Trujillo Emparedados y helados</td> <td>Ana Trujillo</td> <td>Avda. de la Constitución 2222</td> <td>México D.F.</td> <td>05021</td> <td>Mexico</td> </tr>
<tr>
<td>3</td> <td>Antonio Moreno Taquería</td> <td>Antonio Moreno</td> <td>Mataderos 2312</td> <td>México D.F.</td> <td>05023</td> <td>Mexico</td> </tr>
<tr>
<td>4<br/><br/>
</td> <td>Around the Horn</td> <td>Thomas Hardy</td> <td>120 Hanover Sq.</td> <td>London</td> <td>WA1 1DP</td> <td>UK</td> </tr>
<tr>
<td>5</td> <td>Berglunds snabbköp</td> <td>Christina Berglund</td> <td>Berguvsvägen 8</td> <td>Luleå</td> <td>S-958 22</td> <td>Sweden</td> </tr>
</table>
<h2>SQL MID() 实例</h2> <p>下面的 SQL 语句从 "Customers" 表的 "City" 列中提取前 4 个字符:</p> <div class="example margin-b-10"> <h2 class="example">实例</h2> <pre><code class="language-sql"><div class="example_code notranslate"> SELECT MID(City,1,4) AS ShortCity<br/>FROM Customers; </div></code></pre> </div> <div class="text-center padding-10 margin-t-5">
</div>
</div>