zoukankan      html  css  js  c++  java
  • sql中将分隔字符串转为临时表的方法

    问题: 要求将 一字符串 0,1,2,3,4,5 ;将,分隔后的每一内容转为一行记录到数据库表中
    declare  @table_串转数组 table( adapt_object int default 0)
    declare @tmp_str   varchar(100)
    declare @tmp_index int
    select  @tmp_index = 1
    select  @tmp_str = '0,1,12,03,4,5,a,,,'   --赋测试值
    while (@tmp_index > 0)
    begin
       select @tmp_index = CHARINDEX(',', @tmp_str)  --,为分隔符
       if (@tmp_index > 0)  
       if (ISNUMERIC(substring(@tmp_str, 1, @tmp_index - 1)) = 1) --只把是分隔转换后是数字类型的放入到临时表中
       insert into @table_串转数组(adapt_object)  
       select convert(int, substring(@tmp_str, 1, @tmp_index - 1))
       select  @tmp_str  = substring(@tmp_str, @tmp_index + 1, 100) 
    end
    select * from @table_串转数组

  • 相关阅读:
    JQ选择器
    设计模式
    招银网络面试
    斗鱼面经
    招银科技面经
    用户访问网站基本流程
    shell的条件判断
    crontab -e 和/etc/crontab的区别
    秘钥对登录配置
    CentOS6 x86_64最小化安装优化脚本
  • 原文地址:https://www.cnblogs.com/bigmouthz/p/1007330.html
Copyright © 2011-2022 走看看