select ... into ... from (select ... from ...) a,(select ... from ...) b where a.??=b.??
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; 是没问题的。 为什么到了建立存储过程的时候就不行呢?
那么用select (select .....) into pout from ...... 是不是就不行?为什么呀?
在存储过程中没有select ... from ...这样的语法,必须是select ... into ... from ...select ... from ...只能出现在一个结果集中
那么我要实现 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;请问如何实现好呢?
select ... from ... where ...在游标中是可以的啊
那么我要实现 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;请问如何实现好呢?
那么我要实现 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;请问如何实现好呢? 错误如同我发的第一篇帖子。
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); 你试一下。感觉你的表设计挺别扭。
但是我的目的不是为了优化我的查询,
而是想用子查询怎么实现。
这条语句如果在sqlplus里用
select (select 1 from dual) from wz_ygxx_tb where ygh=123;
是没问题的。
为什么到了建立存储过程的时候就不行呢?
是不是就不行?为什么呀?
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;请问如何实现好呢?
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;请问如何实现好呢?
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;请问如何实现好呢?
错误如同我发的第一篇帖子。
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);
你试一下。感觉你的表设计挺别扭。