有两张表:
表a:
 name(全名),no
表b:
 name其中 b表中的name 可能等于或者like  a表中的name。现在想把b.name全变换成对应的a.no。
应该如何编程呢??看似简单,已经花了我半天时间了,头都昏了。哪位大虾援手,必给50分!!

解决方案 »

  1.   

    update  b set b.name=a.no where b.name like a.name and rownum=1;
      

  2.   

    晕哟,要是b的一个字段同时like A里面的两个,B里面怎么Update?比如
    A'abcd',1
    'bbcd',2
    B
    'bcd'
    B Update成1还是2?
      

  3.   

    这个是b.name包含或等于a.name
    update b set b.name =(select a.no from a where instr(b.name,a.name)>0 );如果是a.name包含或等于b.name
    update b set b.name =(select a.no from a where instr(a.name,b.name)>0 );
    如果是互相包含的可能
    update b set b.name= (select a.no from a where instr(a.name,b.name)>0 or instr(b.name,a.name)>0) 
      

  4.   

    难啊
    假如B中的NAME在A中有两个LIKE的记录取哪一个?是不是随便放一个 
    要是的这样的话
    update  b set b.name=
    (select a.no from a where b.name like a.name||'%' and rownum=1);
      

  5.   


    select id,name from d
    1 张三
    2 李四
    3 王五select name from e


    王五

    四--sql:
    select id,b,a
    from 
           (select id,d.name b,e.name a,
                    (case when instr(d.name,e.name)>0 then id end ) nn
                     from d,e 
           )               
     where nn is not null--result:
    2 李四 李
    1 张三 张
    3 王五 王五
    1 张三 三
    2 李四 四
      

  6.   

    instr(d.name,e.name)>0 or instr(e.name,d.name)>0少了一个条件!
      

  7.   

     
    UPDATE B
       SET B.NAME = (SELECT A.NO
                       FROM A
                      WHERE INSTR(B.NAME, A.NAME) > 0
                        AND ROWNUM = 1)
     WHERE EXISTS (SELECT A.NO
              FROM A
             WHERE INSTR(B.NAME, A.NAME) > 0
               AND ROWNUM = 1);