刚开始接触ORACLE,用习惯了MS SQL.老是碰到问题.我创建了一个存储过程.目的是根据两个表关联出记录.然后根据参数取指定记录.但始终不对.把所有的记录都显示出来了:(
 表1 relation_list 表  seller buyer
 表2 buyerInfo 表      buyer,*....
存储过程如下:CREATE OR REPLACE PROCEDURE listBuyerInfo(
--输入参数:
  thisBuyer in varchar2, --客户号
--输出参数:
  v_cur out dotnet.type_cur
)
AS 
begin  
  open v_cur for              
    select * from  
     ( select c.buyer,s.*
        from  relation_list c,
         buyerInfo s where  c.buyer(+)=s.buyer
      ) t   where t.buyer=thisBuyer   ;       
end listBuyerInfo;按理解应该是对的.不知道哪儿错了.还有.怎么能优化一下这个SQL吗?
比如能不能在关联的时候这样写: 
select c.buyer,s.*
    from  (select * from relation_list where relation_list.buyer=thisBuyer) c,
    buyerInfo s where  c.buyer(+)=s.buyer
郁闷死了.求各位达人帮忙!!

解决方案 »

  1.   

    为什么加入了where t.buyer=thisBuyer 这个条件,还是把所以的记录都取出来了??不解.
      

  2.   

    select c.buyer,s.*
            from  relation_list c,
             buyerInfo s where  c.buyer(+)=s.buyer
    中有c.buyer,s.buyer
    你后面的t.buyer指的是哪个啊?
      

  3.   

    select * from  
         ( select c.buyer,s.*
            from  relation_list c,
             buyerInfo s where  c.buyer(+)=s.buyer
          ) t   where t.buyer=thisBuyer   ;    我是把括号里的select 表命名为了t 呀.
      

  4.   

    在s中去掉了buyer还是不行.而且加入where t.buyer=thisBuyer 这个条件,应该只有相符的值才会提取出来啊.求大家给点正解,急~~~
      

  5.   

    不知道怎么没按条件取,不过你可以去掉子查询的select c.buyer,s.*
    from  relation_list c,buyerInfo s 
    where  c.buyer(+)=s.buyer
    and s.buyer = thisBuyer
      

  6.   

    按你的说法应该是
    先判断select count(*) into vcount from buyerInfo where buyer=thisBuyer;
    if vcount>0
    返回select * from relation_list where buyer=thisBuyer;
    else
    没有返回值
      

  7.   

    终于搞定了..其实写法没错.大家也没错.感觉各位达人的帮助.
    原因是传入参数buyer好像不能与表中字段同名.优先好像是认为是字段.所以那个条件永远为真.把所有的都提出来了..汗!!