ORA-00600错误

[复制链接]
查看11 | 回复6 | 2013-10-25 08:53:56 | 显示全部楼层 |阅读模式
select t.po_header_id,t.po_line_id,
sum(decode(t.transaction_type,'RECEIVE',t.quantity,'RETURN TO VENDOR',-t.quantity,0)) rcv_sum_qty,
sum(decode(t.transaction_type,'DELIVER',t.quantity,'RETURN TO RECEIVING',-t.quantity,0))dev_sum_qty
from po.rcv_transactions t
start with (t.organization_id = 32
--and t.transaction_date between to_date('2013-01-01','yyyy-mm-dd') and to_date('2013-01-31','yyyy-mm-dd')

AND t.po_header_id in (
select pb.po_header_id
from po.po_vendors pa,

po.po_headers_all pb
where pb.org_id = 31
and pa.vendor_id = pb.vendor_id
and pa.vendor_name like '%凯凯%'
)


and t.parent_transaction_id = -1)
connect by prior t.transaction_id =t.parent_transaction_id
group by t.po_header_id,t.po_line_id

回复

使用道具 举报

千问 | 2013-10-25 08:53:56 | 显示全部楼层
in那里的子查询,会返回多少条记录,不多的话,就先把子查询固化;多的话,就自己改写成关联。
如果还有错,那就试试把connect by的结果外面再套一层再group by
回复

使用道具 举报

千问 | 2013-10-25 08:53:56 | 显示全部楼层
select distinct t.po_header_id,t.po_line_id,
sum(decode(t.transaction_type,'RECEIVE',t.quantity,'RETURN TO VENDOR',-t.quantity,0))over(partition by t.po_header_id,t.po_line_id order by null) rcv_sum_qty,
sum(decode(t.transaction_type,'DELIVER',t.quantity,'RETURN TO RECEIVING',-t.quantity,0)) over(partition by t.po_header_id,t.po_line_id order by null)dev_sum_qty
from po.rcv_transactions t
start with (t.organization_id = 32
--and t.transaction_date between to_date('2013-01-01','yyyy-mm-dd') and to_date('2013-01-31','yyyy-mm-dd')

AND t.po_header_id in (
select pb.po_header_id
from po.po_vendors pa,

po.po_headers_all pb
where pb.org_id = 31
and pa.vendor_id = pb.vendor_id
and pa.vendor_name like '%凯凯%'
)


and t.parent_transaction_id = -1)
connect by prior t.transaction_id =t.parent_transaction_id
这样写就没问题


select t.po_header_id,t.po_line_id,
sum(decode(t.transaction_type,'RECEIVE',t.quantity,'RETURN TO VENDOR',-t.quantity,0)) rcv_sum_qty,
sum(decode(t.transaction_type,'DELIVER',t.quantity,'RETURN TO RECEIVING',-t.quantity,0))dev_sum_qty
from po.rcv_transactions t
start with (t.organization_id = 32
--and t.transaction_date between to_date('2013-01-01','yyyy-mm-dd') and to_date('2013-01-31','yyyy-mm-dd')

AND (t.transaction_date BETWEEN TO_DATE('${接收时间从}','YYYY-MM-DD') AND TO_DATE('${到}','YYYY-MM-DD'))


and t.parent_transaction_id = -1)
connect by prior t.transaction_id =t.parent_transaction_id
group by t.po_header_id,t.po_line_id
这样也没问题,觉得很奇怪啊
回复

使用道具 举报

千问 | 2013-10-25 08:53:56 | 显示全部楼层
本来600就是cbo改写语句导致的,像connect by这种绕一点的,被改错了也很正常
回复

使用道具 举报

千问 | 2013-10-25 08:53:56 | 显示全部楼层
把in条件放where里就ok了;
还有个问题 :这里的 having 统计不准,要放到外层去判断。
低版本的oracle桑不起啊
selectt.po_header_id,t.po_line_id,
sum(decode(t.transaction_type,'RECEIVE',t.quantity,'RETURN TO VENDOR',-t.quantity,0))rcv_sum_qty,
sum(decode(t.transaction_type,'DELIVER',t.quantity,'RETURN TO RECEIVING',-t.quantity,0)) dev_sum_qty
from po.rcv_transactions t
where t.po_header_id in (
select pb.po_header_id
from po.po_vendors pa,

po.po_headers_all pb
where pb.org_id = 31
and pa.vendor_id = pb.vendor_id
and pa.vendor_name like '%凯凯%'
)
start with (t.organization_id = 32


and t.parent_transaction_id = -1)
connect by prior t.transaction_id =t.parent_transaction_id
--having (sum(decode(t.transaction_type,'RECEIVE',t.quantity,'RETURN TO VENDOR',-t.quantity,0)) - sum(decode(t.transaction_type,'RECEIVE',t.quantity,'RETURN TO VENDOR',-t.quantity,0))) > 0
group by t.po_header_id,t.po_line_id
回复

使用道具 举报

千问 | 2013-10-25 08:53:56 | 显示全部楼层
udfrog 发表于 2014-1-23 10:38
in那里的子查询,会返回多少条记录,不多的话,就先把子查询固化;多的话,就自己改写成关联。
如果还有错 ...

in返回记录数根据查询条件有的会非常多
connect by的结果外面再套一层再group by也没用
回复

使用道具 举报

千问 | 2013-10-25 08:53:56 | 显示全部楼层
zixinsu 发表于 2014-1-23 12:31
把in条件放where里就ok了;
还有个问题 :这里的 having 统计不准,要放到外层去判断。
低版本的oracle桑 ...

你把start with的条件放到where里?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行