我的表中有这么个字段,格式为:A@@B@@C我的要求将这个字段的值变为多条,即:1.A
                                    2.B
                                    3.C
在不用存储过程的情况下,用以条SQL写出来,
现在唯一能确定的是@@是分隔符,其他的都不确定
所以要求要写灵活一点我自己写出一个,不够灵活所以希望看看大家有什么好怕方法没有,谢谢!

解决方案 »

  1.   

    那就是字符串分割嘛,一条sql,估计有难度
      

  2.   

    。。我不太想用存储过程,所以写出来大家讨论一下
    我自己写出了。。不过太长了
    相当于一个动态SQL的存储过程了。。
      

  3.   

    不用PLSQL怎么保持abc呢,保持在数据库中也要保持多次啊。一条sql怎么搞定?
    秀下你的成果,学习下。
      

  4.   

    itemValues=split(字段,"@@") 
    for m=0 to ubound(itemValues)
      if itemValues(m)="" then
       exit for
      end if
     
     canshu=canshu+"∵item∴"+(m+1)+"、"+itemValues(m)
             response.Write(canshu)
     
    next
    这是asp中的  改成java试试
      

  5.   


    这个在JAVA很好实现的,主要是要用查出来的数据做其他运算和统计,所以希望在数据直接做
      

  6.   

    select * from ed_survey t where regexp_like(t.answer, '@@');
    with splitData as(
      select *
        from (select s.questionnum,
                     s.year,
                     decode(sign(t1.c_count),
                            1,
                            substr(s.answer, 1, t2.c_length),
                            0,
                            null,
                            null) a1,
                     decode(sign(t1.c_count - 1),
                            1,
                            substr(s.answer, t2.c_length + 3, t2.c_length),
                            0,
                            substr(s.answer, t2.c_length + 3, t2.c_length),
                            null) a2,
                     decode(sign(t1.c_count - 2),
                            1,
                            substr(s.answer, t2.c_length + 3, t2.c_length),
                            0,
                            substr(s.answer, t2.c_length + 3, t2.c_length),
                            null) a3
                from ed_survey s,
                     (select t0.questionnum,
                             (length(t0.answer) -
                             length(replace(t0.answer, '@@', null))) / 2 c_count
                        from ed_survey t0
                       where regexp_like(t0.answer, '@@')) t1,
                     (select t.questionnum, instr(t.answer, '@@') - 1 c_length
                        from ed_survey t
                       where regexp_like(t.answer, '@@')) t2
               where s.questionnum = t2.questionnum
                 and s.questionnum = t1.questionnum) checks), createData as (select d.questionnum,
                                                                                    d.year,
                                                                                    d.a1 answer
                                                                               from splitData d
                                                                             union all
                                                                             select d.questionnum,
                                                                                    d.year,
                                                                                    d.a2 answer
                                                                               from splitData d
                                                                             union all
                                                                             select d.questionnum,
                                                                                    d.year,
                                                                                    d.a3 answer
                                                                               from splitData d)
      select * from createData where answer is not null;由于现在需求最多只有15个连接,所以我直接写死了
    我现在就想和大家讨论下能否把decode和union all这两个地方写活
    要不以后需求一变,得改代码
      

  7.   

    一条SQL搞出来?太有难度了。
      

  8.   

    为什么一定要用一条sql语句处理,先处理再对数据库操作或是先查询再处理,不行吗,楼主?
      

  9.   

    无语,
    去oracle开发版,点名要wildwave(狂浪)给你搞定。
      

  10.   

    一条sql搞出来难度太大,即使搞出来了估计也是相当耗时的。不如先查询后处理方便。
      

  11.   


    select substring_index('a@@b@@c', '@@', 1) 
    union 
    select right(substring_index('a@@b@@c', '@@', 2),1) 
    union 
    select right(substring_index('a@@b@@c', '@@', 3),1);
    :P 你可以看看这样有没有扩展的可能
    MySQL的
      

  12.   

    估计狂浪也搞不定。请问有谁能在一条SQL命令中能开出可变的栈空间来吗?