select 1 into pout from wz_ygxx_tb where ygh=pygh;这不就行了,干什么写那么复杂

解决方案 »

  1.   

    首先要感谢ORARichard(没钱的日子......) 
    但是我的目的不是为了优化我的查询,
    而是想用子查询怎么实现。
      

  2.   

    select ... into ... from (select ... from ...) a,(select ... from ...) b where a.??=b.??
      

  3.   

    select (select 1 from dual) into pout from wz_ygxx_tb where ygh=pygh;
    这条语句如果在sqlplus里用
    select (select 1 from dual) from wz_ygxx_tb where ygh=123;
    是没问题的。
    为什么到了建立存储过程的时候就不行呢?
      

  4.   

    那么用select (select .....) into pout from ......
    是不是就不行?为什么呀?
      

  5.   

    在存储过程中没有select ... from ...这样的语法,必须是select ... into ... from ...select ... from ...只能出现在一个结果集中
      

  6.   

    那么我要实现
    open mycurcor for select yg.xm,
    decode(yg.jsmc,'领导',(select count(*) from aaa where aaa.ygh=pygh),
    '科员',(select count(*) from bbb where bbb.ygh=pygh),
    ......
    0) tempcount 
    from wz_ygxx_tb where yg.ygh=pygh;请问如何实现好呢?
      

  7.   

    select ... from ... where ...在游标中是可以的啊
      

  8.   

    那么我要实现
    open mycurcor for select yg.xm,
    decode(yg.jsmc,'领导',(select count(*) from aaa where aaa.ygh=pygh),
    '科员',(select count(*) from bbb where bbb.ygh=pygh),
    ......
    0) tempcount 
    from wz_ygxx_tb where yg.ygh=pygh;请问如何实现好呢?
      

  9.   

    那么我要实现
    open mycurcor for select yg.xm,
    decode(yg.jsmc,'领导',(select count(*) from aaa where aaa.ygh=pygh),
    '科员',(select count(*) from bbb where bbb.ygh=pygh),
    ......
    0) tempcount 
    from wz_ygxx_tb where yg.ygh=pygh;请问如何实现好呢?
    错误如同我发的第一篇帖子。
      

  10.   

    select rst.xm, decode(rst.jsmc,'领导',rst1.Num,'科员',rst2.Num) tempcount
    from wz_ygxx_tb rst,
        (select count(*) Num from aaa group by aaa.ygh) rst1,
        (select count(*) Num from bbb group by bbb.ygh) rst2
    where rst.ygh=pygh and (rst1.ygh=pygh or rst2.ygh=pygh);
    你试一下。感觉你的表设计挺别扭。