GOTO (Transact 您所在的位置:网站首页 goto语句语法 GOTO (Transact

GOTO (Transact

2023-10-20 00:32| 来源: 网络整理| 查看: 265

GOTO (Transact-SQL) 项目 05/30/2023

适用于:SQL ServerAzure SQL 数据库Azure SQL 托管实例

将执行流更改到标签处。 跳过 GOTO 后面的 Transact-SQL 语句,并从标签位置继续处理。 GOTO 语句和标签可在过程、批处理或语句块中的任何位置使用。 GOTO 语句可嵌套使用。

Transact-SQL 语法约定

语法 Define the label: label: Alter the execution: GOTO label

注意

若要查看 SQL Server 2014 及更早版本的 Transact-SQL 语法,请参阅早期版本文档。

参数

label 如果 GOTO 语句指向该标签,则其为处理的起点。 标签必须符合标识符规则。 无论是否使用 GOTO 语句,标签均可作为注释方法使用。

备注

GOTO 可出现在条件控制流语句、语句块或过程中,但它不能跳转到该批以外的标签。 GOTO 分支可跳转到定义在 GOTO 之前或之后的标签。

权限

GOTO 语句的权限默认情况下授予任何有效用户。

示例

以下示例显示如何将 GOTO 用作分支机制。

DECLARE @Counter int; SET @Counter = 1; WHILE @Counter < 10 BEGIN SELECT @Counter SET @Counter = @Counter + 1 IF @Counter = 4 GOTO Branch_One --Jumps to the first branch. IF @Counter = 5 GOTO Branch_Two --This will never execute. END Branch_One: SELECT 'Jumping To Branch One.' GOTO Branch_Three; --This will prevent Branch_Two from executing. Branch_Two: SELECT 'Jumping To Branch Two.' Branch_Three: SELECT 'Jumping To Branch Three.'; 另请参阅

控制流语言 (Transact-SQL) BEGIN...END (Transact-SQL) BREAK (Transact-SQL) CONTINUE (Transact-SQL) IF...ELSE (Transact-SQL) WAITFOR (Transact-SQL) WHILE (Transact-SQL)



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有