zoukankan      html  css  js  c++  java
  • 替换一个数据库中的关键字

    declare @SqlStr varchar(8000)
    declare @SQLStrForU varchar(8000)

    declare @TableName varchar(50)
    declare @TableID bigint

    declare @ColumnName varchar(50)


    declare auth_cur cursor for
    select Name,object_id from sys.all_objects where Type='U'
    open auth_cur
    fetch next from auth_cur into @TableName,@TableID
    while (@@fetch_status=0)
    begin
    set @SqlStr='select '
    set @SQLStrForU='update '+@TableName+' set '
    declare auth_cur1 cursor for
    select a.Name from sys.all_columns a join sys.types b
    on a.system_type_id=b.system_type_id
    where a.object_id=@TableID and b.Name in('varchar','char','nvarchar')
    open auth_cur1
    fetch next from auth_cur1 into @ColumnName
    while (@@fetch_status=0)
    begin
    set @SqlStr=@SqlStr+@ColumnName+','
    set @SQLStrForU=@SQLStrForU+@ColumnName+'=replace('+@ColumnName+',''成都市'',''北京市''),'
    fetch next from auth_cur1 into @ColumnName
    end
    close auth_cur1
    deallocate auth_cur1
    set @SqlStr=substring(@SqlStr,1,len(@SqlStr)-1)
    set @SQLStrForU=substring(@SQLStrForU,1,len(@SQLStrForU)-1)

    set @SqlStr=@SqlStr+' from '+@TableName
    print @SQLStrForU

    exec(@SQLStrForU)

    fetch next from auth_cur into @TableName,@TableID
    end
    close auth_cur
    deallocate auth_cur

  • 相关阅读:
    oracle的commit
    struts2 Action 接收参数的三种方法
    git -速查表
    Windows 手动创建 服务
    Linux 上 安装 composer
    Class文件解析
    Java 从数据库中查找信息导入Excel表格中
    将Java Web项目部署到远程主机上
    Java8 map和reduce
    group By 和 Union 、 Union all的用法
  • 原文地址:https://www.cnblogs.com/xiaoruilin/p/5315144.html
Copyright © 2011-2022 走看看