oracle  AA表字段A存储的内容为01,02,03,04这种,01及02、03等分别对应另一个表B中的B字段,如何写SQL将AA表的A字段如何替换为A,B,C,D(A、B、C、D对应B表的C字段)

解决方案 »

  1.   

    原数据长什么样,预期结果又是什么样,用excel 画一下。
      

  2.   

    用excel写下原始值跟最终要的结果
      

  3.   

    replace(replace(replace(字段,'01','A'),'02','B'),'03','C')
      

  4.   

    我这个值不是固定的01 或者02,是另一个表的数据字段比如ID生成的拼接串,要替换为另一个表ID对应的比如NAME字段
      

  5.   

    with tab1 as (
    select '01,02' id from dual 
    )
    ,tab2 as (
    select '01' id, 'A' des from dual union all
    select '02' id, 'B' des from dual
    )
    ,tab3 as (
    select regexp_substr(t1.id, '[^,]+', 1, level) r_id, level lv, t1.id from tab1 t1
    connect by t1.id = prior t1.id
    and prior sys_guid() is not null
    and level <= regexp_count(t1.id, ',') + 1
    )
    select t1.id, listagg(t2.des, ',') within group(order by t1.lv) from tab3 t1, tab2 t2
    where t1.r_id = t2.id
    group by t1.id
    ;
      

  6.   

    SELECT B.C,AA.字段 FROM AA LEFT JOIN B ON AA.A=B.B
      

  7.   

    update aa set id=decode('01','A','02','B',......)
      

  8.   

    这应该是你想要的,通过b表的name字段去更新aa表的id字段update aa set id = (select bb.name from bb where aa.id = bb.id)
    where exists (select 1 from bb where aa.id =bb.id)