select  t_info.INVOICE_NO as HOKEN_Y_KBN1,
t_code1.code_data1 as T1CODE_DATA1
from  Q02D_INVOICE_INFO t_info,
      Q02MCODE t_code1 
where  t_info.HOKEN_Y_KBN=t_code1.code_code(+) 
and  'M123'=t_code1.code_mstkbn(+)
and     t_code1.code_data3(+)='123'
select  t_info.INVOICE_NO as HOKEN_Y_KBN1,
t_code1.code_data1 as T1CODE_DATA1
from  Q02D_INVOICE_INFO t_info,
      (select code_data1,code_code,code_mstkbn,code_data3 from Q02MCODE where code_mstkbn='M123' and code_data3='123')  t_code1 
where  t_info.HOKEN_Y_KBN=t_code1.code_code(+) 上面两个语句结果是一样的,但我认为下面更加合理,不知大家意见如何?

解决方案 »

  1.   

    如果'M123'=t_code1.code_mstkbn后面的加号没有的话,如果t_code1.code_mstkbn没有M123的数据,整条记录就会没有,加的话记录有只是t_code1.code_data1 处为空,哪个更加符合用户需求呢?
      

  2.   

    加与不加(+)的含义是不同的,仅仅当Q02D_INVOICE_INFO.HOKEN_Y_KBN在表Q02MCODE中都存在时,下面两个语句的结果才是相同的。
    select  t_info.HOKEN_Y_KBN as HOKEN_Y_KBN1,
    t_code1.code_data1 as T1CODE_DATA1
    from  Q02D_INVOICE_INFO t_info,
    Q02MCODE t_code1 
    where  t_info.HA_TORISAKI_CD='FZ013' 
    and  t_info.HA_JIGYO_CD='13' 
    and  t_info.INVOICE_NO='IVNO003' 
    and  t_info.HOKEN_Y_KBN=t_code1.code_code(+) 
    and  'M123'=t_code1.code_mstkbn(+);select  t_info.HOKEN_Y_KBN as HOKEN_Y_KBN1,
    t_code1.code_data1 as T1CODE_DATA1
    from  Q02D_INVOICE_INFO t_info,
    Q02MCODE t_code1 
    where  t_info.HA_TORISAKI_CD='FZ013' 
    and  t_info.HA_JIGYO_CD='13' 
    and  t_info.INVOICE_NO='IVNO003' 
    and  t_info.HOKEN_Y_KBN=t_code1.code_code(+) 
    and  'M123'=t_code1.code_mstkbn;
      

  3.   

    楼上的两个语句是有差别:
    'M123'=t_code1.code_mstkbn会过滤掉code_mstkbn<>‘M123’的数据,而'M123'=t_code1.code_mstkbn(+)不会过滤掉code_mstkbn<>‘M123’的数据,不匹配的t_code1.code_data1 就会取空值