<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>MySQL中文参考手册- 7 MySQL 语言参考</title>
<style type="text/css">
<!--
.p14{font-size:14.8px;font-family:宋体;line-height:14pt;}
a:hover{color:red;}
a.t1:visited{color:red;}
-->
</style>
</head>
<body BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#101090" VLINK="#7030B0" class="p4">
<h1><img src="Img/mysql-logo.gif" alt="mysql-logo.gif (3082 bytes)" WIDTH="127" HEIGHT="60"><font color="#FF0000">MySQL中文参考手册</font></h1>
<p>译者:晏子 <a href="mailto:(clyan@sohu.com">(clyan@sohu.com</a>)
主页:<a href="http://linuxdb.yeah.net">http://linuxdb.yeah.net</a></p>
<hr>
<p><a HREF="manual_Introduction.html">第一章</a>, <a HREF="manual_Privilege_system.html">前一章</a>, <a HREF="manual_Tutorial.html">下一章</a>,
<a HREF="manual_Concept_Index.html">最后一章</a>,<a HREF="manual_toc.html">目录</a>.
</p>
<hr>
<h1><a NAME="Reference" HREF="manual_toc.html#Reference">7 MySQL语言参考</a></h1>
<p><a NAME="IDX153"></a> <a NAME="IDX154"></a> </p>
<h2><a NAME="Literals" HREF="manual_toc.html#Literals">7.1
文字:怎么写字符串和数字</a></h2>
<h3><a NAME="String_syntax" HREF="manual_toc.html#String_syntax">7.1.1 字符串</a></h3>
<p>一个字符串是一个字符序列,由单引号(<samp>“'”</samp>)或双引号(<samp>“"”</samp>)字符(后者只有你不在ANSI模式运行)包围。例如:</p>
<pre>'a string'
"another string"
</pre>
<p>在字符串内,某个顺序有特殊的意义。这些顺序的每一个以一条反斜线(<samp>“\”</samp>)开始,称为<em>转义字符</em>。<strong>MySQL</strong>识别下列转义字符:
<dl compact>
<dt><code>\0</code> </dt>
<dd><a name="IDX155"></a>一个ASCII 0 (<code>NUL</code>)字符。 <a name="IDX157"></a><a name="IDX158"></a> </dd>
<dt><code>\n</code> </dt>
<dd>一个新行符。 <a name="IDX159"></a><a name="IDX160"></a> </dd>
<dt><code>\t</code> </dt>
<dd>一个定位符。 <a name="IDX161"></a><a name="IDX162"></a><a name="IDX163"></a> </dd>
<dt><code>\r</code> </dt>
<dd>一个回车符。 <a name="IDX164"></a><a name="IDX165"></a> </dd>
<dt><code>\b</code> </dt>
<dd>一个退格符。 <a name="IDX166"></a><a name="IDX167"></a> </dd>
<dt><code>\'</code> </dt>
<dd>一个单引号(<samp>“'”</samp>)符。 <a name="IDX168"></a><a name="IDX169"></a> </dd>
<dt><code>\"</code> </dt>
<dd>一个双引号(<samp>“"”</samp>)符。 <a name="IDX170"></a><a name="IDX171"></a>
</dd>
<dt><code>\\</code> </dt>
<dd>一个反斜线(<samp>“\”</samp>)符。 <a name="IDX172"></a><a name="IDX173"></a> </dd>
<dt><code>\%</code> </dt>
<dd>一个“<samp>%”</samp>符。它用于在正文中搜索“%”的文字实例,否则这里“%”将解释为一个通配符。
<a name="IDX174"></a><a name="IDX175"></a> </dd>
<dt><code>\_</code> </dt>
<dd>一个“<samp>_”</samp>符。它用于在正文中搜索“_”的文字实例,否则这里“_”将解释为一个通配符。</dd>
</dl>
<p>注意,如果你在某些正文环境中使用<samp>“\%”</samp>或<samp>“\%_”</samp>,这些将返回字符串<samp>“\%”</samp>和<samp>“\_”</samp>而不是<samp>“%”</samp>和<samp>“_”</samp>。
</p>
<p>有几种方法在一个字符串内包括引号:
<ul>
<li>一个字符串内用“'”加引号的“'”可以被写作为<samp>“''”</samp>。
</li>
<li>一个字符串内用<samp>“"”加引号</samp>的<samp>“"”</samp>可以被写作为<samp>“""”</samp>。
</li>
<li>你可以把一个转义字符(“\”)放在引号前面。 </li>
<li>一个字符串内用<samp>“"”</samp>加引号<samp>的“'”</samp>不需要特殊对待而且不必被重复或转义。同理,<samp>一个字符串内用“'”加引号的</samp>与<samp>“"”</samp>也不需要特殊对待。
</li>
</ul>
<p>下面显示的<code>SELECT</code>演示引号和转义如何工作: </p>
<pre>mysql> SELECT 'hello', '"hello"', '""hello""', 'hel''lo', '\'hello';
+-------+---------+-----------+--------+--------+
| hello | "hello" | ""hello"" | hel'lo | 'hello |
+-------+---------+-----------+--------+--------+
mysql> SELECT "hello", "'hello'", "''hello''", "hel""lo", "\"hello";
+-------+---------+-----------+--------+--------+
| hello | 'hello' | ''hello'' | hel"lo | "hello |
+-------+---------+-----------+--------+--------+
mysql> SELECT "This\nIs\nFour\nlines";
+--------------------+
| This
Is
Four
lines |
+--------------------+
<a NAME="IDX176"></a> </pre>
<p>如果你想要把二进制数据插入到一个<code>BLOB</code>列,下列字符必须由转义序列表示:
<dl compact>
<dt><code>NUL</code></dt>
<dd>ASCII 0。你应该用'\0'(一个反斜线和一个ASCII '0')表示它。 </dd>
<dt><code>\</code> </dt>
<dd>ASCII 92,反斜线。用'\\'表示。 </dd>
<dt><code>'</code> </dt>
<dd>ASCII 39,单引号。用“\'”表示。 </dd>
<dt><code>"</code> </dt>
<dd>ASCII 34,双引号。用“\"”表示。 </dd>
</dl>
<p><a NAME="IDX177"></a>如果你写C代码,你可以使用C API函数<code>mysql_escape_string()</code>来为<code>INSERT</code>语句转义字符。见<a HREF="manual_Clients.html#C_API_function_overview">20.3 C API 函数概述</a>。在 Perl中,你可以使用<code>DBI</code>包中的<code>quote</code>方法变换特殊的字符到正确的转义序列。见<a HREF="manual_Clients.html#Perl_DBI_Class">20.5.2 <code>DBI</code>接口</a>。 </p>
<p>你应该在任何可能包含上述任何特殊字符的字符串上使用转义函数!
</p>
<h3><a NAME="Number_syntax" HREF="manual_toc.html#Number_syntax">7.1.2 数字</a></h3>
<p>整数表示为一个数字顺序。浮点数使用<samp>“.”</samp>作为一个十进制分隔符。这两种类型的数字可以前置<samp>“-”</samp>表明一个负值。
</p>
<p>有效整数的例子: </p>
<pre>
1221
0
-32
</pre>
<p>有效浮点数的例子: </p>
<pre>
294.42
-32032.6809e+10
148.00
</pre>
<p>一个整数可以在浮点上下文使用;它解释为等值的浮点数。 </p>
<h3><a NAME="Hexadecimal_values" HREF="manual_toc.html#Hexadecimal_values">7.1.3
十六进制值</a></h3>
<p><strong>MySQL</strong>支持十六进制值。在数字上下文,它们表现类似于一个整数(64位精度)。在字符串上下文,它们表现类似于一个二进制字符串,这里每一对十六进制数字被变换为一个字符。
</p>
<pre>mysql> SELECT 0xa+0
-> 10
mysql> select 0x5061756c;
-> Paul
</pre>
<p>十六进制字符串经常被ODBC使用,给出BLOB列的值。 </p>
<h3><a NAME="NULL_values" HREF="manual_toc.html#NULL_values">7.1.4<code> NULL</code>值</a></h3>
<p><code>NULL</code>值意味着“无数据”并且不同于例如数字类型的<code>0</code>为或字符串类型的空字符串。见<a HREF="manual_Problems.html#Problems_with_NULL">18.15 <code>NULL</code>值问题</a>。 </p>
<p>当使用文本文件导入或导出格式(<code>LOAD DATA INFILE</code>, <code>SELECT
... INTO OUTFILE</code>)<code>时,NULL</code>可以用<code>\N</code>表示。见<a HREF="manual_Reference.html#LOAD_DATA">7.16<code> LOAD DATA INFILE</code>句法</a>。</p>
<h3><a NAME="Legal_names" HREF="manual_toc.html#Legal_names">7.1.5
数据库、表、索引、列和别名的命名</a></h3>
<p>数据库、表、索引、列和别名的名字都遵守<strong>MySQL</strong>同样的规则:
</p>
<p><a NAME="IDX183"></a><a NAME="IDX185"></a>注意,从<strong>MySQL</strong>3.23.6开始规则改变了,此时我们引入了用'引用的标识符(数据库、表和列命名)(如果你以ANSI模式运行,"也将用于引用标识符)。
</p>
<table BORDER="1" WIDTH="100%" NOSAVE="#101090" class="p4">
<tr>
<td><strong>标识符</strong> </td>
<td><strong>最大长度</strong> </td>
<td><strong>允许的字符</strong> </td>
</tr>
<tr>
<td>数据库</td>
<td>64</td>
<td>在一个目录名允许的任何字符,除了<code>/</code>. </td>
</tr>
<tr>
<td>表</td>
<td>64</td>
<td>在文件名中允许的任何字符,除了<code>/</code>或<code>.</code> </td>
</tr>
<tr>
<td>列</td>
<td>64</td>
<td>所有字符</td>
</tr>
<tr>
<td>别名</td>
<td>255</td>
<td>所有字符</td>
</tr>
</table>
<p>注意,除了以上,你在一个标识符中不能有ASCII(0)或ASCII(255)。 </p>
<p>注意,如果标识符是一个限制词或包含特殊字符,当你使用它时,你必须总是用<code>`</code>引用它:
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
MySQL中文参考手册(HTM) (144个子文件)
Thumbs.db 47KB
Thumbs.db 47KB
mysql-logo.gif 3KB
mysql-logo.gif 3KB
great-britain.gif 1KB
great-britain.gif 1KB
usa.gif 731B
usa.gif 731B
australia.gif 689B
australia.gif 689B
south-korea.gif 663B
south-korea.gif 663B
brazil.gif 662B
brazil.gif 662B
croatia.gif 659B
croatia.gif 659B
south-africa1.gif 650B
south-africa1.gif 650B
portugal.gif 633B
portugal.gif 633B
canada.gif 407B
canada.gif 407B
singapore.gif 389B
singapore.gif 389B
taiwan.gif 377B
taiwan.gif 377B
chile.gif 370B
chile.gif 370B
japan.gif 357B
japan.gif 357B
greece.gif 282B
greece.gif 282B
czech-republic.gif 248B
czech-republic.gif 248B
switzerland.gif 237B
switzerland.gif 237B
china.gif 224B
china.gif 224B
iceland.gif 197B
iceland.gif 197B
sweden.gif 193B
sweden.gif 193B
finland.gif 192B
finland.gif 192B
denmark.gif 187B
denmark.gif 187B
france.gif 158B
ireland.gif 158B
romania.gif 158B
italy.gif 158B
france.gif 158B
ireland.gif 158B
romania.gif 158B
italy.gif 158B
bulgaria.gif 141B
russia.gif 141B
bulgaria.gif 141B
russia.gif 141B
spain.gif 138B
spain.gif 138B
ukraine.gif 132B
poland.gif 132B
austria.gif 132B
ukraine.gif 132B
poland.gif 132B
austria.gif 132B
germany.gif 126B
estonia.gif 126B
germany.gif 126B
estonia.gif 126B
preface.htm 2KB
preface.htm 2KB
manual_Reference.html 258KB
manual_Reference.html 258KB
manual_Installing.html 155KB
manual_Installing.html 155KB
manual_News.html 130KB
manual_News.html 130KB
manual_Clients.html 108KB
manual_Clients.html 108KB
manual_Tutorial.html 70KB
manual_Tutorial.html 70KB
manual_Performance.html 69KB
manual_Performance.html 69KB
manual_Privilege_system.html 63KB
manual_Privilege_system.html 63KB
manual_toc.html 55KB
manual_toc.html 55KB
manual_Function_Index.html 42KB
manual_Function_Index.html 42KB
manual_Problems.html 40KB
manual_Problems.html 40KB
manual_Introduction.html 39KB
manual_Introduction.html 39KB
manual_Tools.html 32KB
manual_Tools.html 32KB
manual_Maintenance.html 31KB
manual_Maintenance.html 31KB
manual_Contrib.html 26KB
manual_Contrib.html 26KB
共 144 条
- 1
- 2
flymanhi
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0