我正在尝试创建一个过程,该过程将返回串联的值,但会出错。
我创建了一个过程名称“ GetMultiVal”,并在其中创建了用于获取值的游标“ stage_val”。
High Street, Luton
Business Name, London
期望:应在v_var_value变量中获取串联值。
实际:获取错误PROCEDURE DBPROD.GETMULTIVAL的编译错误
错误:PLS-00103:预期以下情况之一时遇到符号“ FOR”:
答案 0 :(得分:2)
如果在for循环中使用游标,则无需打开游标。
尝试这个:
CREATE OR REPLACE PROCEDURE getmultival(v_var_value out varchar2
,v_hr_stk_out out Sys_Refcursor) is
var_value varchar2(200);
x varchar2(200);
cursor age_val is
SELECT age_cd
,decode(age_cd, '07', 'CLNE(RW', '05', 'CS ', '4A', NULL, age_desc) age_desc
,age_seq
FROM dbprod.prod_age_mst
WHERE age_seq < 15
AND age_cd NOT IN ('6A', '05')
ORDER BY 3;
BEGIN
open v_hr_stk_out for
SELECT age_cd
,decode(age_cd, '07', 'CLNE(RW', '05', 'CS ', '4A', NULL, age_desc) age_desc
,age_seq
FROM dbprod.prod_age_mst
WHERE age_seq < 15
AND age_cd NOT IN ('6A', '05')
ORDER BY 3;
FOR i IN age_val LOOP
SELECT to_char(round(nvl(SUM(nvl(rod_wt, 0)), 0), 0))
INTO x
FROM dbprod.prod_age_fgs_cur
WHERE wf_date BETWEEN sysdate AND sysdate + 1
AND wf_age_cd = i.age_cd;
var_value := var_value || x || '~';
END LOOP;
v_var_value := var_value ;
end;
答案 1 :(得分:0)
我试图重新建立您的程序:
CREATE OR REPLACE PROCEDURE GETMULTIVAL (
V_VAR_VALUE OUT VARCHAR2,
V_HR_STK_OUT OUT SYS_REFCURSOR
) IS
VAR_VALUE VARCHAR2(200);
X VARCHAR2(200);
-- CURSOR AGE_VAL IS
-- SELECT
-- AGE_CD,
-- DECODE(AGE_CD, '07', 'CLNE(RW', '05', 'CS ', '4A', NULL, AGE_DESC) AGE_DESC,
-- AGE_SEQ
-- FROM
-- DBPROD.PROD_AGE_MST
-- WHERE
-- AGE_SEQ < 15
-- AND AGE_CD NOT IN (
-- '6A',
-- '05'
-- )
-- ORDER BY
-- 3;
BEGIN
OPEN V_HR_STK_OUT FOR
SELECT
AGE_CD,
DECODE(AGE_CD, '07', 'CLNE(RW', '05', 'CS ', '4A', NULL, AGE_DESC) AGE_DESC,
AGE_SEQ
FROM
DBPROD.PROD_AGE_MST
WHERE
AGE_SEQ < 15
AND AGE_CD NOT IN (
'6A',
'05'
)
ORDER BY
3;
-- FOR i IN age_val LOOP
-- SELECT to_char(round(nvl(SUM(nvl(rod_wt, 0)), 0), 0))
-- INTO x
-- FROM dbprod.prod_age_fgs_cur
-- WHERE wf_date BETWEEN sysdate AND sysdate + 1
-- AND wf_age_cd = i.age_cd;
-- var_value := var_value || x || '~';
-- END LOOP;
SELECT
LISTAGG(ROUND(NVL(SUM(NVL(ROD_WT, 0)), 0), 0), '~') WITHIN GROUP(
ORDER BY
M.AGE_SEQ
)
INTO VAR_VALUE
FROM
DBPROD.PROD_AGE_MST M
JOIN DBPROD.PROD_AGE_FGS_CUR A ON ( A.WF_AGE_CD = M.AGE_CD )
WHERE
A.WF_DATE BETWEEN SYSDATE AND SYSDATE + 1
AND M.AGE_SEQ < 15
AND M.AGE_CD NOT IN (
'6A',
'05'
);
V_VAR_VALUE := VAR_VALUE;
END;
无需定义显式游标即可找到V_VAR_VALUE
的值,可以使用单个联接来实现。
在我的数据库中对其进行测试,因为我没有任何示例数据和DDL。
希望,这将为解决方案指明方向。
干杯!