4.1. Lexical Structure

4.1. Lexical Structure

4.1. 词法结构

SQL input consists of a sequence of commands. A command is composed of a sequence of tokens,terminated by a semicolon (“;”). The end of the input stream also terminates a command. Which tokens are valid depends on the syntax of the particular command.

SQL包含一系列命令。命令由一些列标记组成,并以分号结尾。结束符结束了该命令。哪些标记可用取决于特定命令的语法。

A token can be a key word, an identifier, a quoted identifier, a literal (or constant), or a special character symbol. Tokens are normally separated by whitespace (space, tab, newline), but need not be if there is no ambiguity (which is generally only the case if a special character is adjacent to some other token type).

标记可以是关键词,标识符,带引号的标识符,文字(或常量),或者一个特殊字符。标记通常以 空格(空格,tab,换行)分隔,但如果不存在歧义的话,也可以不加空格(通常只有特殊字符与一些标记类型相邻才是这种情况)。

For example, the following is (syntactically) valid SQL input:

例如,以下为正确(语法上)SQL语句:

扫描二维码关注公众号,回复: 9213881 查看本文章

SELECT * FROM MY_TABLE;

UPDATE MY_TABLE SET A = 5;

INSERT INTO MY_TABLE VALUES (3, 'hi there');

This is a sequence of three commands, one per line (although this is not required; more than one command can be on a line, and commands can usefully be split across lines).

这是三条命令,每行一条命令(虽然这不是必须的;一行可以有多个命令,也可以的行之间有效的拆分命令)

Additionally, comments can occur in SQL input. They are not tokens, they are effectively equivalent to whitespace.

而且,SQL中可以写注解。它们并不是标记,注解可以认为等同于空格而在执行时被忽略。

The SQL syntax is not very consistent regarding what tokens identify commands and which are operands or parameters. The first few tokens are generally the command name, so in the above example we would usually speak of a “SELECT”, an “UPDATE”, and an “INSERT” command. But for instance the UPDATE command always requires a SET token to appear in a certain position, and this particular variation of INSERT also requires a  VALUES in order to be complete. The precise syntax rules for each command are described in Part VI.

关于哪些标记标识命令以及哪些是操作数或参数,SQL语法并不一致。前几个标记一般是命令名字,所以对于上面的示例,我们一般称为select、update和insert命令。但是,update命令一般需要一个set,而insert一般需要一个values标记。命令的详细语法请参见第六部分

发布了341 篇原创文章 · 获赞 53 · 访问量 88万+

猜你喜欢

转载自blog.csdn.net/ghostliming/article/details/104172494