如何使用with子句向select语句添加额外的列

时间:2014-02-06 03:44:12

标签: oracle11g

如何将 V_SP_CDRA_WEEKLY_UPDATE.indication 列添加到以下sql语句中。截至目前,它只显示str_out列。任何帮助将不胜感激。

 with
    transformation(str_in,flag,str_out) as
    (select  substr(s,instr(s,'href=') + 5),1,cast(substr(s,1,instr(s,'href=') + 4) as varchar2(4000))
    from (select  KEY_DOCUMENTS s From V_SP_CDRA_WEEKLY_UPDATE Where KEY_DOCUMENTS like '%%https:%%')
    union all
    select substr(str_in,2),
            case when flag = 1
                  and substr(str_in,1,1) != '>'
                 then 1
                 when substr(str_in,1,1) = '>'
                 then 0
                 when substr(str_in,1,5) = 'href='
                 then 1
                 else 0
            end,
            str_out || case when substr(str_in,1,1) = ' '
                             and flag = 1
                            then '%20'
                            else substr(str_in,1,1)
                       end
       from transformation
      where length(str_in) > 0
    )
    select str_out
      from transformation
    where str_in is null;

1 个答案:

答案 0 :(得分:0)

我不知道你的数据,所以我试着问你的问题:

with
    transformation(str_in, flag, str_out, indication) as
       (select  substr(s,instr(s,'href=') + 5),
                1,
                cast(substr(s,1,instr(s,'href=') + 4) as varchar2(4000)),
                i
        from (select KEY_DOCUMENTS s, indication i
              From V_SP_CDRA_WEEKLY_UPDATE
              Where KEY_DOCUMENTS like '%%https:%%')
        union all
        select substr(str_in,2),
               case when flag = 1  and substr(str_in,1,1) != '>'
                    then 1
                    when substr(str_in,1,1) = '>'
                    then 0
                    when substr(str_in,1,5) = 'href='
                    then 1
                    else 0
               end,
               str_out || case when substr(str_in,1,1) = ' '   and flag = 1
                               then '%20'
                               else substr(str_in,1,1)
                          end,
               null as i
        from transformation
        where length(str_in) > 0)
select str_out, indication
from transformation
where str_in is null;