0

このフォーラムは初めてです。エラーが発生しました

エラー - ORA-00907: 右括弧がありません

クエリを実行しようとすると、この問題の解決を手伝ってください。以下のクエリを見つけてください。よろしくお願いします!

私は以下のように関数を書いています -

create or replace
function ATOS_GET_GDC_ROLLUP (p_gdc in varchar, p_year in number, p_userid in number, p_gdcpara in varchar) return ATOS_CAPACITY_ROLLUP_TYPE_SI
as

v_capacity_rollup_si ATOS_CAPACITY_ROLLUP_TYPE_SI;
v_name varchar2(255);
v_month varchar2(20);
v_budget number;
v_supply number;
v_pipeline number;
v_demand number;
v_monthtext varchar2(3);
v_monthvalue number;

i number;

code number;

CURSOR c_get_capacity_rollup IS select par.INVESTMENT,
decode(par.partime,null,children.childtime,par.par time),
decode(par.BUDGET,null,children.BUDGET,0,children. BUDGET,par.BUDGET),
decode(par.SUPPLYSIDE,null,children.SUPPLYSIDE,0,c hildren.SUPPLYSIDE,par.SUPPLYSIDE),
decode(par.PIPELINE,null,children.PIPELINE,0,child ren.PIPELINE,par.PIPELINE),
decode(par.DEMANDSIDE,null,children.DEMANDSIDE,0,c hildren.DEMANDSIDE,par.DEMANDSIDE),
case (decode(par.monthvalue,null,children.monthvalue,pa r.monthvalue))
when 1 then 'Jan'
when 2 then 'Feb'
when 3 then 'Mar'
when 4 then 'Apr'
when 5 then 'May'
when 6 then 'Jun'
when 7 then 'Jul'
when 8 then 'Aug'
when 9 then 'Sep'
when 10 then 'Oct'
when 11 then 'Nov'
when 12 then 'Dec'
else ''
end as monthtext,
(decode(par.monthvalue,null,children.monthvalue,pa r.monthvalue)) monthvalue
from 
(select
(budp.periodyear || '-' || lpad(budp.periodnumber, 2, '0')) partime,
reqp.name INVESTMENT,
budp.budget BUDGET,
budp.actual SUPPLYSIDE,
budp.user1 PIPELINE,
budp.user4 DEMANDSIDE,
budp.periodnumber monthvalue
from tr_request reqp
inner join tr_resourcebudget budp on reqp.requestid = budp.requestid
where budp.periodyear= p_year 
and reqp.requestid = (select I_GDC.REQUESTID
from TR_REQUEST I_GDC
where I_GDC.NAME = p_gdcpara
and A7_GET_RQV (I_GDC.REQUESTID, 'Investment Category', 'C') = 'Global Delivery Centre (GDC)'
and (p_gdc = 'ALL' or p_gdc = I_GDC.NAME)
and exists (select null
from TR_REQUESTACCESS RA
where RA.REQUESTID = I_GDC.REQUESTID
and RA.RESOURCEID = p_userid)))par
FULL OUTER JOIN
(select 
(budc.periodyear || '-' || lpad(budc.periodnumber, 2, '0')) childtime,
SUM(budc.budget) BUDGET,
SUM(budc.actual) SUPPLYSIDE,
SUM(budc.user1) PIPELINE,
SUM(budc.user4) DEMANDSIDE,
budc.periodnumber monthvalue
from tr_request reqc
inner join tr_resourcebudget budc on reqc.requestid = budc.requestid
where budc.periodyear= p_year 
and reqc.requestid IN (SELECT requestid FROM TR_REQUEST
WHERE CONNECT_BY_ISLEAF=1
CONNECT BY PRIOR requestid = parentid
START WITH requestid = (select I_GDC.REQUESTID
from TR_REQUEST I_GDC
where I_GDC.NAME = p_gdcpara
and A7_GET_RQV (I_GDC.REQUESTID, 'Investment Category', 'C') = 'Global Delivery Centre (GDC)'
and (p_gdc = 'ALL' or p_gdc = I_GDC.NAME)
and exists ( select null
from TR_REQUESTACCESS RA
where RA.REQUESTID = I_GDC.REQUESTID
and RA.RESOURCEID = p_userid)))
group by budc.periodnumber, (budc.periodyear || '-' || lpad(budc.periodnumber, 2, '0')))children
ON par.partime = children.childtime;


begin

if not c_get_capacity_rollup%ISOPEN then
open c_get_capacity_rollup;
end if;

i := 0;
v_capacity_rollup_si := ATOS_CAPACITY_ROLLUP_TYPE_SI();

loop
fetch c_get_capacity_rollup into v_name, v_month, v_budget, v_supply, v_pipeline, v_demand, v_monthtext,v_monthvalue;

exit when c_get_capacity_rollup%NOTFOUND;

i := i + 1;
v_capacity_rollup_si.extend(1);
v_capacity_rollup_si(i) := ATOS_CAPACITY_ROLLUP_RECORD_SI(v_name, v_month, v_budget, v_supply, v_pipeline, v_demand, v_monthtext, v_monthvalue);

end loop;
close c_get_capacity_rollup;

return v_capacity_rollup_si;

end ATOS_GET_GDC_ROLLUP;
/

クエリの下で実行すると:-

select * from table(ATOS_GET_GDC_ROLLUP('India',2013,400,'India' ))

18 行目と 91 行目で段落エラーが発生しています。しかし、カーソルのクエリを実行すると、正しい出力が得られます。括弧のバランスが取れていることを確認します。上記のクエリで何が間違っているか教えてください。詳細が必要な場合はお知らせください。

以下のバージョンを使用しています-

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
"CORE   10.2.0.1.0  Production"
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
4

1 に答える 1

1

The error you're getting doesn't always mean there's an unmatched bracket. Sometimes the compiler throws that error when we have made a syntax error and it finds a keyword it is not expecting when it has an unpaired left bracket.

But then you say:

"when i run query for cursor then i am getting correct output.I confirm that parenthesis are balanced."

Hmmm, okay then the problem is likely to be this:

"Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod"

That is the unpatched first release of 10gR2. Normally we would expect to be able to run in PL/SQL any query which we can run in SQL. However, there are sometimes bugs, especially in the initial version of a major release, which break the contract.

There have been three or four major patch sets (depending on your OS) over the years. Anybody still running on the original release is presumably doing so because they don't have a support contract and so can't patch their database. If so, that rules out upgrading your database as a potential solution.

The only other thing you can do is debug your query. It is extremely complicated with lots of nested sub-queries (and lots of parentheses). It is likely to be something in the depths of those sub-queries which is causing the problem. So, start removing some of the complexity from your query and seeing when your query starts working. Then you know which bit of logic you need to rewrite.

The other thing to try is simplifying the procedure. You don't need all that CURSOR and LOOP infrastructure. You could just use Plain Old SQL Query with BULK COLLECT to populate v_capacity_rollup_si. Or extract the query from the procedure and hide it behind a view. Either of these things might solve the problem, because the problem is the interaction between SQL and PL/SQL, and not the actual query.

于 2013-06-17T13:00:20.070 に答える