这是我在9i中的SQL语句,现在要换到8i中,由于8i不支持left join语句,没办法,只能改写了.
select T1.bgbh,T1.wtdw,T1.symc,
T1.ggxh,T1.jclb,T1.spbh,T1.jcrq,T2.stid,T2.zmc  
from whvri_zjz_base T1 
left join whvri_zjz_other T2 on T2.stid = T1.stid 
where T1.bgbh like '%变压器%' or T1.bgbh like '%变压器%' or T1.wtdw like '%变压器%' 
or  T1.symc like '%变压器%' or T1.ggxh like '%变压器%' 
or T1.jclb like '%变压器%' or T1.spbh like '%变压器%' or T1.jcrq 
like '%变压器%' or T1.stid like '%变压器%'
or T1.bgbh like '%变压器%' order by T1.bgbh二个表通过stid来进行关联,T2中只有三个字段 id ,stid,zmc(stid编号对应的名称),我改写后总是出现重复信息,使用group by后也不行.急.

解决方案 »

  1.   

    刚没理解好你的意思.这样可以了.自己弄了个例子
    create table t1(id varchar(10),name varchar(10));
    create table t2(id varchar(10),name varchar(10));
    insert into t1 values('1','a');
    insert into t1 values('2','b');
    insert into t1 values('3','c');
    insert into t1 values('4','d');
    insert into t2 values('1','x');
    insert into t2 values('2','y');select * from t1,t2 where t1.id=t2.id union 
    select t1.*,null id ,null name from t1 where t1.id not in(select id from t2)
      

  2.   

    解决了,oracle8i不支持left join,但支持(+)
    把or运算全部用()括起来,就OK了
    select T1.bgbh,T1.wtdw,T1.symc,
    T1.ggxh,T1.jclb,T1.spbh,T1.jcrq,T2.stid,T2.zmc  
    from whvri_zjz_base T1,whvri_zjz_other T2 where T2.stid = T1.stid(+) 
    and (T1.bgbh like '%变压器%' or T1.bgbh like '%变压器%' or T1.wtdw like '%变压器%' 
    or  T1.symc like '%变压器%' or T1.ggxh like '%变压器%' 
    or T1.jclb like '%变压器%' or T1.spbh like '%变压器%' or T1.jcrq 
    like '%变压器%' or T1.stid like '%变压器%'
    or T1.bgbh like '%变压器%') order by T1.bgbh
    这是改写的可以运行于oracle 8i的
    谢谢大家的回复