MySQL reference manual.docx_第1页
MySQL reference manual.docx_第2页
MySQL reference manual.docx_第3页
MySQL reference manual.docx_第4页
MySQL reference manual.docx_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

13.6.1 BEGINEND Compound-Statement Syntaxbegin_label: BEGINstatement_listEND end_labelBEGIN . END syntax is used for writing compound statements, which can appear within stored programs(stored procedures and functions, triggers, and events). A compound statement can contai-n multiple statements, enclosed by the BEGIN and END keywords. statement_list represents a list of one or more statement, each terminated by a semicolon(;)statement delimiter. The statement_list itself is optional, so the empty compound statement (BEGIN END) is legal.BEGIN . END语句是用于合成语句的,里面可以出现存储的程序(存储过程、函数、触发器和事件)。在BEGIN和END关键字里的范围里一个合成语句里可以包含多条语句。statement_list关键字表示一条或多条语句的列表集合,每条语句结束标志为分号(;)语句定界符。这个语句列表是可选的,所以空的语句也是合法的。BEGIN . END blocks can be nested.Use of multiple statements requires that a client is able to send statement strings containing the; statement delimiter. In the mysql command-line client, this is handled with the delimiter command. Changing the; end-of-statement delimiter (for example, to /) permit; to be used in a program body. For an example, see Section18.1, “Defining Stored Programs”.A BEGIN . END block can be labeled. See Section13.6.2, “Statement Label Syntax”.The optional NOT ATOMIC clause is not supported. This means that no transactional savepoint is set at the start of the instruction block and the BEGIN clause used in this context has no effect on the current transaction. NoteWithin all stored programs, the parser treats BEGIN WORKas the beginning of a BEGIN . END block. To begin a transaction in this context, use START TRANSACTION instead.BEGINEND模块是可以嵌套的。使用多条语句则需要一个客户端能发送包含语句定界符;的语句字符串。在mysql命令行客户端中,这个用delimiter命令来处理。改变分号作为语句结尾定界符(举个例子,改为/)允许分号用于一个程序体中。举一个例子,查看18.1章节,“Defining Stored Programs”。一个BEGIN.END模块式可以有标签的。查看13.6.2章节,“Statement Label Syntax“。可选项NOTATOMIC子句是不被支持的,这个意思是说在开始语句模块没有事务保存点并且BEGIN子句在该语境中使用对当前的事务不会有影响。备注:在所有的存储程序中,语句把BEGINWORK作为一个BEGINEND模块的开始。而在这种语境中开始一个事务则用START TRANSACTION替代。13.6.2.Statement Label Syntaxbegin_label: BEGIN statement_listEND end_labelbegin_label: LOOP statement_listEND LOOP end_labelbegin_label: REPEAT statement_listUNTIL search_conditionEND REPEAT end_labelbegin_label: WHILE search_condition DO statement_listEND WHILE end_labelLabels are permitted for BEGIN . END blocks and for the LOOP, REPEAT, and WHILE statements. Label use for those statements follows these rules: begin_label must be followed by a colon. begin_label can be given without end_label. If end_label is present, it must be the same as begin_label. end_label cannot be given without begin_label. Labels at the same nesting level must be distinct. Labels can be up to 16 characters long. 在BEGINEND模块中允许使用标签,在LOOP,REPEAT和WHILE语句也同样允许。对于这些语句的标签使用必须遵循以下规则: begin_label必须后接一个冒号。 begin_label可以在没有用end_label的时候使用。如果出现了end_label,那么就必须使用相同标签的作为begin_label。 end_label不能再没有begin_label的时候单独使用。 标签在相同的嵌套级别必须标识清楚。 标签最大可达16字符长。To refer to a label within the labeled construct, use an ITERATE or LEAVE statement. The following example uses those statements to continue iterating or terminate the loop: CREATE PROCEDURE doiterate (p1 INT)BEGIN label1: LOOP SET p1 = p1 + 1; IF p1 m THEN SET s = ; ELSEIF n = m THEN SET s = =; ELSE SET s = m THEN SET s = greater; ELSE SET s = less; END IF; SET s = CONCAT (is , s, than); END IF; SET s = CONCAT (n, , s, , m, .); RETURN s; END /DELIMITER ;In this example, the inner IF is evaluated only if n is not equal to m. 在这个例子中,内部的IF只有当n不等于m的时候才求值。13.6.5.3. ITERATE SyntaxITERATE labelITERATE can appear only within LOOP, REPEAT, and WHILE statements. ITERATE means “start the loop again.” For an example, see Section13.6.5.5, “LOOP Syntax”. ITERATE 只能出现在LOOP, REPEAT和WHILE语句中。ITERATE意思为“开始重复一次这个循环”。查看Section13.6.5.5, “LOOP Syntax”例子。13.6.5.4. LEAVE SyntaxLEAVE labelThis statement is used to exit the flow control construct that has the given label. If the label is for the outermost stored program block, LEAVE exits the program. LEAVE can be used within BEGIN . END or loop constructs (LOOP, REPEAT, WHILE). For an example, see Section13.6.5.5, “LOOP Syntax”. 这个语句用来退出流程构造中给出的标签。如果这个标签在存储程序模块的最外层,LEAVE退出这个程序。LEAVE可以用来在BEGIN . END之中或者循环构造(LOOP, REPEAT, WHILE)中。查看Section13.6.5.5, “LOOP Syntax”的例子。13.6.5.5. LOOP Syntaxbegin_label: LOOP statement_listEND LOOP end_labelLOOP implements a simple loop construct, enabling repeated execution of the statement list, which consists of one or more statements, each terminated by a semicolon (;) statement delimiter. The statements within the loop are repeated until the loop is terminated. Usually, this is accomplished with a LEAVE statement. Within a stored function, RETURN can also be used, which exits the function entirely. Neglecting to include a loop-termination statement results in an infinite loop. A LOOP statement can be labeled. For the rules regarding label use, see Section13.6.2, “Statement Label Syntax”. LOOP实现一个简单的循环构建,使之能够重复执行语句列表,一个由一条或多条语句组成的列表,每句由分号(;)语句终止符结尾。这些在循环中的语句一直重复执行直到循环结束。一般,由LEAVE语句来完成结束循环。在一个存储函数中,RETURN也可以使用,用于完全退出函数。忘了在循环中加入循环终止语句的结果就是会有一个无限循环。Example: CREATE PROCEDURE doiterate (p1 INT)BEGIN label1: LOOP SET p1 = p1 + 1; IF p1 delimiter /mysql CREATE PROCEDURE dorepeat(p1 INT) - BEGIN - SET x = 0; - REPEAT - SET x = x + 1; - UNTIL x p1 END REPEAT; - END - /Query OK, 0 rows affected (0.00 sec)mysql CALL dorepeat(1000)/Query OK, 0 rows affected (0.00 sec)mysql SELECT x/+-+| x |+-+| 1001 |+-+1 row in set (0.00 sec)13.6.5.7. RETURN SyntaxRETURN exprThe RETURN statement terminates execution of a stored function

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论