zoukankan      html  css  js  c++  java
  • Sql 转义字符 游标 CTE(With)

    http://www.cnblogs.com/zhengchuyu/archive/2008/07/23/1249422.htmlhttp://www.javaeye.com/topic/155109#

    Sql语法中的转义字符:

    第一个:‘,如果字符串中出现单引号 ’,则用两个单引号代替它,达到转义的目的。 《‘’》

    第二个:对于字符串中出现的特殊字符:'%','[','[]', '_' 可以使用 '[]' 把它们包含起来,这样在匹配模式(pattern)中,它们就被当作普通字符对待了。

    第三个:在like中使用escape,对于其他的特殊字符:'^', '-', ']' 因为它们本身在包含在 '[]' 中使用,所以需要用另外的方式来转义,于是就引入了 like 中的 escape 子句,另外值得注意的是:escape 可以转义所有的特殊字符。

    游标

    if (object_id ('tb' ) is not null )
        drop table tb
    go
    create table tb (id int identity (1 , 1 ), name varchar (10 ), tag int default 0 )
    insert into tb (name ) select 'a'
    insert into tb (name ) select 'b'
    insert into tb (name ) select 'c'
    insert into tb (name ) select 'd'
    insert into tb (name ) select 'e'

    --声明游标 select 后的条目要和Fetch Next into后面的一致

    declare myCursor cursor
    for select Id,Name from tb


    declare @Id nvarchar(20),
            @name nvarchar(20)

    --打开游标
    open myCursor

    --从光标中筛出当前行
    Fetch Next from  myCursor
    into @Id,@name

    --通过判断@@FETCH_STATUS=0来循环,@@FETCH_STATUS指示最后一次Fetch操作成功还是失败,0代表成功

    While(@@FETCH_STATUS=0)

    End
    select @Id,@name

    --关闭游标
    close myCursor
    Deallocate myCursor

  • 相关阅读:
    Makefile Special Built-in Target Names(Makefile内建特殊目标)
    著名的变量命名规则
    bottle py
    LuCI中文手册
    LuCI
    LuCI2 (OpenWrt web 管理界面)
    LuCI2 (OpenWrt web user interface)
    OpenWrt netifd
    加载时间/性能
    Taming the asynchronous beast with ES7
  • 原文地址:https://www.cnblogs.com/zqstc/p/1662527.html
Copyright © 2011-2022 走看看