感谢你们这些天的帮助,我希望我能帮助至少一个人,但我不会在这里恭喜你们。
当我尝试检查数据库上某些进程的状态时,我遇到了问题
我提出了一个问题:
DECLARE
CLAVES varchar(12);
FECHA date;
BEGIN
FECHA := TO_DATE('16/10/2015','DD/MM/YYYY');
FOR KEYS IN (
SELECT SKEY,
SUBSTR(RPAD(COD.SCOMMAND,43),41) PROD
FROM INSUDB.BATCH_JOB COD,
INSUDB.BATCH_PROCESS PRO
WHERE COD.NUSERCODE = '3345'
AND COD.NBATCH = PRO.NBATCH
AND COD.NUSERSUBMIT = COD.NUSERCODE
AND TRUNC(COD.DSUBMIT) = TO_DATE ('16/10/2015', 'DD/MM/YYYY')
AND PRO.SCODISPL = 'VIL7002'
ORDER BY COD.DSUBMIT ASC
)LOOP
CLAVES := TRIM(TO_CHAR(KEYS.SKEY));
BEGIN
SELECT '01 - EJEC' " ",
NPRODUCT PRODUCTO,
COUNT(*) CONTAR,
TO_CHAR(NVL(TRUNC(MOD((MAX(DCOMPDATE) - MIN(DCOMPDATE))*24,24 )),0)) ||' HRS. '||
TO_CHAR(NVL(TRUNC(MOD((MAX(DCOMPDATE) - MIN(DCOMPDATE))*24*60,60)),0)) ||' MIN. '||
TO_CHAR(NVL(TRUNC(MOD((MAX(DCOMPDATE) - MIN(DCOMPDATE))*24*60*60,60)),0)) ||' SEG.' TIEMPO,
MIN(DCOMPDATE) ,
MAX(DCOMPDATE)
FROM TIMETMP.TMP_VIL7002
WHERE SKEY = CLAVES
AND NSTATUS = 1
group by nproduct
UNION
SELECT '02 - PEND' COL,
null,
COUNT(*),
NULL,
NULL,
NULL
FROM TIMETMP.TMP_VIL7002
WHERE SKEY = CLAVES
AND NSTATUS <> 1
UNION
SELECT '03 - ERR ' COL,
null,
COUNT(*),
NULL,
NULL,
NULL
FROM TIMETMP.TMP_VIL7002
WHERE SKEY = CLAVES
AND NSTATUS = 3
UNION
SELECT '04 - TOTAL' COL,
null,
COUNT(*),
NULL,
NULL,
NULL
FROM TIMETMP.TMP_VIL7002
WHERE SKEY = CLAVES;
END;
END LOOP;
END;
这只会给我下一条错误消息
END;
Error at line 1
ORA-06550: línea 24, columna 17:
PLS-00428: an INTO clause is expected in this SELECT statement
答案 0 :(得分:1)
这正是消息所说的。如果在PLSQL中执行select语句,则必须对结果执行某些操作。您可以创建一个for循环来迭代它(就像使用第一个查询一样),或者添加一个into子句,在该子句中为查询中的每个列指定一个PLSQL变量。这就是PLSQL在执行内部SQL语句之类的语句时所期望的。
就像现在一样,它只是执行大内部查询而不对其结果做任何事情。而且由于这很愚蠢,PLSQL不允许这样做。
答案 1 :(得分:0)
每当你在PL / SQL中编写SELECT
语句时,你应该使用SELECT INTO
语句,这样结果就可以了。
您可以在此处了解如何制作SELECT INTO
:
http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm
答案 2 :(得分:0)
所以,我最终解决了我的问题,使用此查询并且不使用过程
SELECT SKEY,
SUBSTR(RPAD(COD.SCOMMAND,43),41) PROD,
SUBSTR(RPAD(COD.SCOMMAND,67),66)||'/'||SUBSTR(RPAD(COD.SCOMMAND,65),64)||'/'||SUBSTR(RPAD(COD.SCOMMAND,63),60) FECHA,
(SELECT COUNT(*) FROM TIMETMP.TMP_VIL7002 TMP WHERE TMP.SKEY = COD.SKEY AND NSTATUS = 1) EJECUTADOS,
(SELECT COUNT(*) FROM TIMETMP.TMP_VIL7002 TMP WHERE TMP.SKEY = COD.SKEY AND NSTATUS <> 1) PENDIENTES,
(SELECT COUNT(*) FROM TIMETMP.TMP_VIL7002 TMP WHERE TMP.SKEY = COD.SKEY AND NSTATUS = 3) ERRORES,
(SELECT COUNT(*) FROM TIMETMP.TMP_VIL7002 TMP WHERE TMP.SKEY = COD.SKEY ) TOTAL,
(SELECT MIN(DCOMPDATE) FROM TIMETMP.TMP_VIL7002 TMP WHERE TMP.SKEY = COD.SKEY ) INICIO,
(SELECT MAX(DCOMPDATE) FROM TIMETMP.TMP_VIL7002 TMP WHERE TMP.SKEY = COD.SKEY ) TERMINO
FROM INSUDB.BATCH_JOB COD,
INSUDB.BATCH_PROCESS PRO
WHERE COD.NUSERCODE = '3345'
AND COD.NBATCH = PRO.NBATCH
AND COD.NUSERSUBMIT = COD.NUSERCODE
AND TRUNC(COD.DSUBMIT) = TO_DATE ('18/10/2015', 'DD/MM/YYYY') -- unico parametro a cambiar es la fecha de ejecucion
AND PRO.SCODISPL = 'VIL7002'
ORDER BY COD.DSUBMIT ASC