| company_code | item_code | item_name | cost_class |
| 00 | item1 | name1 | f |
| 00 | item2 | name2 | m |
| 01 | item1 | name1 | m |
| 01 | item2 | name2 | f |
| company_code | item_code | t1 | t2 |
| 00 | item1 | aa | bb |
| 00 | item2 | cc | dd |
| 00 | item3 | ee | ff |
| null | null | null | null |
要求:将xtest2中的数据全部显出,根据xtest2中的公司号及物料代码去xtest1表里找对应的物料名,但是有一个附加条件,就是xtest1表里必须是cost_class='f'的才能写到最后的结果集中。最后实验成功的sql如下:
select a.item_code,b.item_name from xtest2 a,xtest1 b where a.item_code = b.item_code(+) and b.cost_class(+)='f'
and a.company_code = b.company_code(+)
总结:b表的匹配条件还要加一个右连接,要不无法得到想要的结果。
这个语句其实还有个问题,就是如果b表中符合条件的记录比a表多,那得到的结果集会有误,但是在我要的程序结果不用考虑这种情况,哈哈,试验成功!!!开始写程序。

