游标更新在 Oracle 中出现错误
Updation of cursor is giving error in Oracle
我创建了一个包含游标的存储过程。它还会根据一些计算更新 2 列。
程序如下。
CREATE OR REPLACE PROCEDURE FIBER_SIGNOFF_UGAR_UPD AS
BEGIN
for cur_r in (
select inv.CIRCLE,
regexp_substr(MP,'[^/]+',1,1)MPNAME,regexp_substr(MP,'[^/]+',1,2)MPCODE,
inv.ROUTE_APPROVED_BY_CMM as CMM_APPROVED_LENGTH,
inv.SPAN_TYPE, ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4) AS NE_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS UG_LENGTH
,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY LIKE '%AERIAL%' THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS AR_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4)/ ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4)*100 as ug_percentage,
mv.rj_intracity_link_id FROM NE.MV_SPAN@DB_LINK_NE_VIEWER mv
join TBL_FIBER_INV_CMP_REPORT_MV inv
on ((inv.SPAN_TYPE = 'INTERCITY' AND inv.SPAN_LINK_ID = mv.rj_span_id)
or (inv.SPAN_TYPE = 'INTRACITY' AND inv.SPAN_LINK_ID = mv.rj_intracity_link_id)
or (inv.SPAN_TYPE = 'ENTERPRISE' AND inv.SPAN_LINK_ID = mv.rj_intracity_link_id))
GROUP BY mv.rj_intracity_link_id, inv.ROUTE_APPROVED_BY_CMM, inv.SPAN_TYPE,inv.CIRCLE, inv.MP
)
loop
begin
update TBL_FIBER_INV_SIGN_OFF_SHEET set
FSA_UG = cur_r.CMM_APPROVED_LENGTH * cur_r.ug_percentage / 100,
FSA_AERIAL = cur_r.CMM_APPROVED_LENGTH - (cur_r.CMM_APPROVED_LENGTH * cur_r.ug_percentage / 100)
WHERE SPAN_LINK_ID =
CASE cur_r.SPAN_TYPE
WHEN 'INTERCITY' THEN cur_r.rj_span_id
WHEN 'INTRACITY' THEN cur_r.rj_intracity_link_id
WHEN 'ENTERPRISE' THEN cur_r.rj_intracity_link_id
END;
end
end loop;
END FIBER_SIGNOFF_UGAR_UPD;
错误是
Error(33,29): PL/SQL: ORA-00920: invalid relational operator
Error(39,1): PLS-00103: Encountered the symbol "END" when expecting one of the following: ; The symbol ";" was substituted for "END" to continue.
这个 END
少了一个分号:
END; --> here
END LOOP;
END FIBER_SIGNOFF_UGAR_UPD;
从无效关系运算符开始:此 CASE 缺少 关系运算符:
WHERE CASE cur_r.span_type
WHEN 'INTERCITY' THEN cur_r.rj_span_id
WHEN 'INTRACITY' THEN cur_r.rj_intracity_link_id
WHEN 'ENTERPRISE' THEN cur_r.rj_intracity_link_id
END
它等于某物吗?有什么不同?什么?应该是例如
WHERE CASE cur_r.span_type
WHEN 'INTERCITY' THEN cur_r.rj_span_id
WHEN 'INTRACITY' THEN cur_r.rj_intracity_link_id
WHEN 'ENTERPRISE' THEN cur_r.rj_intracity_link_id
END = 1
---
This
试试这个,用 case 语句替换 where 子句
CREATE OR REPLACE PROCEDURE FIBER_SIGNOFF_UGAR_UPD AS
BEGIN
for cur_r in (
select inv.CIRCLE,
inv.MP,
inv.ROUTE_APPROVED_BY_CMM as CMM_APPROVED_LENGTH,
inv.SPAN_TYPE, ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4) AS NE_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS UG_LENGTH
,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY LIKE '%AERIAL%' THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS AR_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4)/ ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4)*100 as ug_percentage,
mv.rj_intracity_link_id FROM NE.MV_SPAN@DB_LINK_NE_VIEWER mv
join TBL_FIBER_INV_CMP_REPORT_MV inv
on ((inv.SPAN_TYPE = 'INTERCITY' AND inv.SPAN_LINK_ID = mv.rj_span_id)
or (inv.SPAN_TYPE = 'INTRACITY' AND inv.SPAN_LINK_ID = mv.rj_intracity_link_id)
or (inv.SPAN_TYPE = 'ENTERPRISE' AND inv.SPAN_LINK_ID = mv.rj_intracity_link_id))
GROUP BY mv.rj_intracity_link_id, inv.ROUTE_APPROVED_BY_CMM, inv.SPAN_TYPE,inv.CIRCLE, inv.MP
)
loop
begin
update TBL_FIBER_INV_SIGN_OFF_SHEET set
FSA_UG = cur_r.CMM_APPROVED_LENGTH * cur_r.ug_percentage / 100,
FSA_AERIAL = cur_r.CMM_APPROVED_LENGTH - (cur_r.CMM_APPROVED_LENGTH * cur_r.ug_percentage / 100)
WHERE SPAN_LINK_ID =
CASE WHEN cur_r.SPAN_TYPE ='INTERCITY' THEN cur_r.rj_span_id
WHEN cur_r.SPAN_TYPE IN('INTRACITY','ENTERPRISE') THEN cur_r.rj_intracity_link_id
END;
end;
end loop;
END FIBER_SIGNOFF_UGAR_UPD;
我创建了一个包含游标的存储过程。它还会根据一些计算更新 2 列。
程序如下。
CREATE OR REPLACE PROCEDURE FIBER_SIGNOFF_UGAR_UPD AS
BEGIN
for cur_r in (
select inv.CIRCLE,
regexp_substr(MP,'[^/]+',1,1)MPNAME,regexp_substr(MP,'[^/]+',1,2)MPCODE,
inv.ROUTE_APPROVED_BY_CMM as CMM_APPROVED_LENGTH,
inv.SPAN_TYPE, ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4) AS NE_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS UG_LENGTH
,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY LIKE '%AERIAL%' THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS AR_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4)/ ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4)*100 as ug_percentage,
mv.rj_intracity_link_id FROM NE.MV_SPAN@DB_LINK_NE_VIEWER mv
join TBL_FIBER_INV_CMP_REPORT_MV inv
on ((inv.SPAN_TYPE = 'INTERCITY' AND inv.SPAN_LINK_ID = mv.rj_span_id)
or (inv.SPAN_TYPE = 'INTRACITY' AND inv.SPAN_LINK_ID = mv.rj_intracity_link_id)
or (inv.SPAN_TYPE = 'ENTERPRISE' AND inv.SPAN_LINK_ID = mv.rj_intracity_link_id))
GROUP BY mv.rj_intracity_link_id, inv.ROUTE_APPROVED_BY_CMM, inv.SPAN_TYPE,inv.CIRCLE, inv.MP
)
loop
begin
update TBL_FIBER_INV_SIGN_OFF_SHEET set
FSA_UG = cur_r.CMM_APPROVED_LENGTH * cur_r.ug_percentage / 100,
FSA_AERIAL = cur_r.CMM_APPROVED_LENGTH - (cur_r.CMM_APPROVED_LENGTH * cur_r.ug_percentage / 100)
WHERE SPAN_LINK_ID =
CASE cur_r.SPAN_TYPE
WHEN 'INTERCITY' THEN cur_r.rj_span_id
WHEN 'INTRACITY' THEN cur_r.rj_intracity_link_id
WHEN 'ENTERPRISE' THEN cur_r.rj_intracity_link_id
END;
end
end loop;
END FIBER_SIGNOFF_UGAR_UPD;
错误是
Error(33,29): PL/SQL: ORA-00920: invalid relational operator Error(39,1): PLS-00103: Encountered the symbol "END" when expecting one of the following: ; The symbol ";" was substituted for "END" to continue.
这个 END
少了一个分号:
END; --> here
END LOOP;
END FIBER_SIGNOFF_UGAR_UPD;
从无效关系运算符开始:此 CASE 缺少 关系运算符:
WHERE CASE cur_r.span_type
WHEN 'INTERCITY' THEN cur_r.rj_span_id
WHEN 'INTRACITY' THEN cur_r.rj_intracity_link_id
WHEN 'ENTERPRISE' THEN cur_r.rj_intracity_link_id
END
它等于某物吗?有什么不同?什么?应该是例如
WHERE CASE cur_r.span_type
WHEN 'INTERCITY' THEN cur_r.rj_span_id
WHEN 'INTRACITY' THEN cur_r.rj_intracity_link_id
WHEN 'ENTERPRISE' THEN cur_r.rj_intracity_link_id
END = 1
---
This
试试这个,用 case 语句替换 where 子句
CREATE OR REPLACE PROCEDURE FIBER_SIGNOFF_UGAR_UPD AS
BEGIN
for cur_r in (
select inv.CIRCLE,
inv.MP,
inv.ROUTE_APPROVED_BY_CMM as CMM_APPROVED_LENGTH,
inv.SPAN_TYPE, ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4) AS NE_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS UG_LENGTH
,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY LIKE '%AERIAL%' THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS AR_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4)/ ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4)*100 as ug_percentage,
mv.rj_intracity_link_id FROM NE.MV_SPAN@DB_LINK_NE_VIEWER mv
join TBL_FIBER_INV_CMP_REPORT_MV inv
on ((inv.SPAN_TYPE = 'INTERCITY' AND inv.SPAN_LINK_ID = mv.rj_span_id)
or (inv.SPAN_TYPE = 'INTRACITY' AND inv.SPAN_LINK_ID = mv.rj_intracity_link_id)
or (inv.SPAN_TYPE = 'ENTERPRISE' AND inv.SPAN_LINK_ID = mv.rj_intracity_link_id))
GROUP BY mv.rj_intracity_link_id, inv.ROUTE_APPROVED_BY_CMM, inv.SPAN_TYPE,inv.CIRCLE, inv.MP
)
loop
begin
update TBL_FIBER_INV_SIGN_OFF_SHEET set
FSA_UG = cur_r.CMM_APPROVED_LENGTH * cur_r.ug_percentage / 100,
FSA_AERIAL = cur_r.CMM_APPROVED_LENGTH - (cur_r.CMM_APPROVED_LENGTH * cur_r.ug_percentage / 100)
WHERE SPAN_LINK_ID =
CASE WHEN cur_r.SPAN_TYPE ='INTERCITY' THEN cur_r.rj_span_id
WHEN cur_r.SPAN_TYPE IN('INTRACITY','ENTERPRISE') THEN cur_r.rj_intracity_link_id
END;
end;
end loop;
END FIBER_SIGNOFF_UGAR_UPD;