Using 10G, I'm trying to use a cursor in the /* Obligated */ area below to check to see if a certain year is in the budget_history table, if it's not then I use the bud_stru_29_lvl_2 table. But I keep getting errors. BTW, this is only a portion of the code
CURSOR c1 IS
SELECT 'Y'
FROM cip.budget_period13_afs2
WHERE ROWNUM < 2
AND fiscalyear = TO_NUMBER(v_cfy-1);
BEGIN
-- Really don't need to set all these, but makes it easier to read ---
v_cur_yr := TO_CHAR (p_fy);
v_cfy := TO_CHAR (p_cfy);
v_yr1 := TO_CHAR (p_fy - 2);
v_yr2 := TO_CHAR (p_fy - 1);
v_yr3 := TO_CHAR (p_fy - 3);
IF p_fy >= p_cfy THEN
SELECT DISTINCT
cip.budget_month_faoao_afs2.MONTH
INTO v_month
FROM cip.budget_month_faoao_afs2;
ELSE
v_month := '12';
END IF;
IF p_permission = 'true' THEN
IF p_mgrempid <> 'All' THEN
INSERT INTO OM_REPORT_COMBSUM_MANAGER(
fund,
agency,
orgn,
manager,
object_cd,
typename,
actuals,
budget,
ytd_expenses,
cye,
basic,
suppreduct_amt,
username)
(select distinct
FDUO.fund,
FDUO.agency,
FDUrg,
FDUO.fullname,
FDUbject_cd,
FDUO.type_name,
sum(nvl(PFY_Obligated.PFYObligated,0)) PFYObligated,
sum(nvl(CFY_Budget.CFYBudget,0)) CFYBudget,
sum(nvl(CFY_AsLastMonthEnd.CFYAsLastMonthEnd,0)) CFYAsLastMonthEnd,
sum(nvl(CYE_TBL.CYE,0)) CYE,
sum(nvl(Proposed_TBL.Proposed,0)) Proposed,
sum(nvl(Suppreduct_TBL.Suppreduct,0)) Suppreduct,
p_username
FROM
(select a.fund, a.agency, a.org, a.object_cd, c.fullname, d.type_name
from cip.budget_period13_afs2 a, om.om_faos b, cip.list_employees c, om.om_objectcd_types d
where a.fund = b.FUND
and a.agency = b.AGENCY
and a.org = b.ORG
and b.EMPID_DIVISIONMANAGER = p_empid
and a.OBJECT_CD = d.OBJECT_CD
and b.FY = p_fy
and (a.FUND, a.agency) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
and a.fiscalyear = v_yr1
UNION
select a.fund_cd, a.dept_cd, a.unit_cd, a.obj_cd, c.fullname, d.type_name
from aims36.BUD_STRU_29_LVL_2 a, om.om_faos b, cip.list_employees c, om.om_objectcd_types d
where a.fund_cd = b.FUND
and a.dept_cd = b.AGENCY
and a.unit_cd = b.ORG
and b.EMPID_DIVISIONMANAGER = p_empid
and a.obj_cd = d.OBJECT_CD
and b.FY = p_fy
and a.bfy = v_cfy
and (a.fund_cd, a.dept_cd) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
UNION
select a.fund, a.agency, a.org, a.object_cd, c.fullname, d.type_name
from cip.budget_history_afs2 a, om.om_faos b, cip.list_employees c, om.om_objectcd_types d
where a.fund = b.FUND
and a.agency = b.AGENCY
and a.org = b.ORG
and b.EMPID_DIVISIONMANAGER = p_empid
and a.object_cd = d.OBJECT_CD
and b.FY = p_fy
and a.fiscalyear = v_cfy
and (a.fund, a.agency) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
UNION
select a.fund, a.agency, a.org, b.object_cd, c.fullname, d.type_name
from om_faos a, om_phaseobject b, cip.list_employees c, om.om_objectcd_types d
where a.om_fao_id = b.om_fao_id
and a.fy between v_cfy and p_fy
and (a.fund, a.agency) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
and a.EMPID_DIVISIONMANAGER = p_empid
and b.object_cd = d.OBJECT_CD
) FDUO,
/* Obligated */
-- IF p_fy > 2006 THEN
-- OPEN c1;
-- FETCH c1 INTO in_result;
-- IF c1%NOTFOUND THEN
-- CLOSE c1;
(select
a.fund_cd,
a.dept_cd,
a.unit_cd,
a.obj_cd,
round((sum(a.ACTU_EXP_AM)+sum(a.ENC_AM)),0) PFYObligated
from aims36.bud_stru_29_lvl_2 a
where (a.fund_cd, a.dept_cd) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
and a.BFY = TO_NUMBER(v_yr1)
having sum(a.ACTU_EXP_AM)+sum(a.ENC_AM) <> 0
group by a.fund_cd, a.dept_cd, a.unit_cd, a.obj_cd) PFY_Obligated,
-- ELSE
-- (select
-- fund,
-- agency,
-- org,
-- object_cd,
-- round((sum(YTDEXPENSE)+sum(ENCUMBERANCE)),0) PFYObligated
-- from cip.budget_period13_afs2
-- where (fund, agency) in (select distinct e.fund, e.agency
-- from om.om_list_deptagencies e
-- where e.DEPT_CD = p_dept_cd)
-- and fiscalyear = v_yr1
-- having sum(YTDEXPENSE)+sum(ENCUMBERANCE) <> 0
-- group by fund, agency, org, object_cd) PFY_Obligated,
-- END IF;
-- END IF;
Thanks,
Sherry
CURSOR c1 IS
SELECT 'Y'
FROM cip.budget_period13_afs2
WHERE ROWNUM < 2
AND fiscalyear = TO_NUMBER(v_cfy-1);
BEGIN
-- Really don't need to set all these, but makes it easier to read ---
v_cur_yr := TO_CHAR (p_fy);
v_cfy := TO_CHAR (p_cfy);
v_yr1 := TO_CHAR (p_fy - 2);
v_yr2 := TO_CHAR (p_fy - 1);
v_yr3 := TO_CHAR (p_fy - 3);
IF p_fy >= p_cfy THEN
SELECT DISTINCT
cip.budget_month_faoao_afs2.MONTH
INTO v_month
FROM cip.budget_month_faoao_afs2;
ELSE
v_month := '12';
END IF;
IF p_permission = 'true' THEN
IF p_mgrempid <> 'All' THEN
INSERT INTO OM_REPORT_COMBSUM_MANAGER(
fund,
agency,
orgn,
manager,
object_cd,
typename,
actuals,
budget,
ytd_expenses,
cye,
basic,
suppreduct_amt,
username)
(select distinct
FDUO.fund,
FDUO.agency,
FDUrg,
FDUO.fullname,
FDUbject_cd,
FDUO.type_name,
sum(nvl(PFY_Obligated.PFYObligated,0)) PFYObligated,
sum(nvl(CFY_Budget.CFYBudget,0)) CFYBudget,
sum(nvl(CFY_AsLastMonthEnd.CFYAsLastMonthEnd,0)) CFYAsLastMonthEnd,
sum(nvl(CYE_TBL.CYE,0)) CYE,
sum(nvl(Proposed_TBL.Proposed,0)) Proposed,
sum(nvl(Suppreduct_TBL.Suppreduct,0)) Suppreduct,
p_username
FROM
(select a.fund, a.agency, a.org, a.object_cd, c.fullname, d.type_name
from cip.budget_period13_afs2 a, om.om_faos b, cip.list_employees c, om.om_objectcd_types d
where a.fund = b.FUND
and a.agency = b.AGENCY
and a.org = b.ORG
and b.EMPID_DIVISIONMANAGER = p_empid
and a.OBJECT_CD = d.OBJECT_CD
and b.FY = p_fy
and (a.FUND, a.agency) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
and a.fiscalyear = v_yr1
UNION
select a.fund_cd, a.dept_cd, a.unit_cd, a.obj_cd, c.fullname, d.type_name
from aims36.BUD_STRU_29_LVL_2 a, om.om_faos b, cip.list_employees c, om.om_objectcd_types d
where a.fund_cd = b.FUND
and a.dept_cd = b.AGENCY
and a.unit_cd = b.ORG
and b.EMPID_DIVISIONMANAGER = p_empid
and a.obj_cd = d.OBJECT_CD
and b.FY = p_fy
and a.bfy = v_cfy
and (a.fund_cd, a.dept_cd) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
UNION
select a.fund, a.agency, a.org, a.object_cd, c.fullname, d.type_name
from cip.budget_history_afs2 a, om.om_faos b, cip.list_employees c, om.om_objectcd_types d
where a.fund = b.FUND
and a.agency = b.AGENCY
and a.org = b.ORG
and b.EMPID_DIVISIONMANAGER = p_empid
and a.object_cd = d.OBJECT_CD
and b.FY = p_fy
and a.fiscalyear = v_cfy
and (a.fund, a.agency) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
UNION
select a.fund, a.agency, a.org, b.object_cd, c.fullname, d.type_name
from om_faos a, om_phaseobject b, cip.list_employees c, om.om_objectcd_types d
where a.om_fao_id = b.om_fao_id
and a.fy between v_cfy and p_fy
and (a.fund, a.agency) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
and a.EMPID_DIVISIONMANAGER = p_empid
and b.object_cd = d.OBJECT_CD
) FDUO,
/* Obligated */
-- IF p_fy > 2006 THEN
-- OPEN c1;
-- FETCH c1 INTO in_result;
-- IF c1%NOTFOUND THEN
-- CLOSE c1;
(select
a.fund_cd,
a.dept_cd,
a.unit_cd,
a.obj_cd,
round((sum(a.ACTU_EXP_AM)+sum(a.ENC_AM)),0) PFYObligated
from aims36.bud_stru_29_lvl_2 a
where (a.fund_cd, a.dept_cd) in (select distinct e.fund, e.agency
from om.om_list_deptagencies e
where e.DEPT_CD = p_dept_cd)
and a.BFY = TO_NUMBER(v_yr1)
having sum(a.ACTU_EXP_AM)+sum(a.ENC_AM) <> 0
group by a.fund_cd, a.dept_cd, a.unit_cd, a.obj_cd) PFY_Obligated,
-- ELSE
-- (select
-- fund,
-- agency,
-- org,
-- object_cd,
-- round((sum(YTDEXPENSE)+sum(ENCUMBERANCE)),0) PFYObligated
-- from cip.budget_period13_afs2
-- where (fund, agency) in (select distinct e.fund, e.agency
-- from om.om_list_deptagencies e
-- where e.DEPT_CD = p_dept_cd)
-- and fiscalyear = v_yr1
-- having sum(YTDEXPENSE)+sum(ENCUMBERANCE) <> 0
-- group by fund, agency, org, object_cd) PFY_Obligated,
-- END IF;
-- END IF;
Thanks,
Sherry