zoukankan      html  css  js  c++  java
  • SQL Server中的流控制语句

    • begin···end

    该语句定义sql代码块,通常在if和while语句中使用

    declare @num int ;
    set @num=0;
    
    while  @num<10
    
    begin
      set @num=@num+1;
      print 'hello word'
    
    end
    • if···else

    条件判断语句,其中else是可选的

    if  (select sex from UserBasic where name='张三')=1
        print '张三的性别是:男'
    else
        print '张三的性别是:女'
    •  while、break、continue
    declare @num int ;
    set @num=0;
    
    while  @num<10
    
    begin
      set @num=@num+1;
      print 'hello word'
        if @num=2
            continue
        if @num=5
            break
    end

    说明:本例输出5行 hello word

    • goto label(自定义标记)

    该语句用来无条件地将语句的执行顺序转到用户定义的lable处

    declare @num int;
    set @num=0;
    
    echo:
        print 'hello word'
    set @num=@num+1;
    
    while  @num<10
    begin
      goto echo
    end
    • return

    该语句用来无条件退出一个查询或一个过程

    declare @num int ;
    set @num=0;
    
    while  @num<10
    
    begin
      set @num=@num+1;
      print 'hello word'
        if @num=5
            return
    end
    • waitfor delay/time

    该语句用来定义某天的一个时刻,执行一个语句块。waitfor delay 'time'表示要等待多长时间,waitfor time 'time'表示要等到哪个时刻执行。

    示例:10秒之后输出‘hello word’

    waitfor delay '00:00:10'
    print 'hello word' 
    
    --
    
    print 'hello word' waitfor delay '00:00:10'

    示例:12:00钟输出‘hello word’

    waitfor time '12:00:00'
    print 'hello word' 
    
    --
    
    print 'hello word' waitfor time '12:00:00'

    SQL Server中的流控制语句介绍的这里。

  • 相关阅读:
    第七周作业
    第六周作业
    第五周作业
    第四周作业
    第三周作业
    第二周作业
    第一周作业
    老鼠与盈利
    币值转换
    2015 USP-ICMC gym 100733 J. Summer Wars
  • 原文地址:https://www.cnblogs.com/paulhe/p/9499879.html
Copyright © 2011-2022 走看看