[英]How can I workaround looping a cursor in Oracle PL/SQL 8i which uses a subscalar query?
I am trying to create a PL/SQL procedure which needs to do a for loop through a cursor.我正在尝试创建一个需要通过游标执行 for 循环的 PL/SQL 过程。 I have read in the oracle forums that PL/SQL 8i doesn't support subscalar queries.我在 oracle 论坛中读到 PL/SQL 8i 不支持子标量查询。
This is what I have so far :这是我到目前为止:
DECLARE
CURSOR C1
IS
SELECT texto,id_evento,clave_evento FROM gegf.eventos_omega_rima WHERE id_evento IN
(select max(eo.id_evento) from gegf.eventos_omega_rima eo, correctivo_rima.equipos b
where eo.fecha_ins_tab > sysdate - 25/24 and eo.fecha_ins_tab < sysdate - 1/24 and upper(eo.ORIGEN) = upper(b.nodo) and upper(b.red) = 'RIMA' group by eo.clave_evento);
r_emp C1%ROWTYPE;
BEGIN
OPEN C1;
LOOP
FETCH c1 INTO r_emp;
EXIT WHEN C1%NOTFOUND;
INSERT INTO CORRECTIVO_RIMA.T_CLOB VALUES (r_emp.TEXTO);
END LOOP;
CLOSE c1;
END;
/
How could I workaround the fact that I can't use subscalar queries in the PL/SQL version I am using?我如何解决无法在我使用的 PL/SQL 版本中使用子标量查询的问题?
The PLS-00103 is telling you where the problem is; PLS-00103 告诉您问题出在哪里; line 6 column 49. In this part of your query:第 6 行第 49 列。在您查询的这一部分中:
where eo.fecha_ins_tab > sysdate - and
... something is missing after the minus sign; ... 减号后缺少某些内容; presumably you're trying to subtract some number of days from today, but you haven't supplied that number.大概你想从今天减去一些天数,但你没有提供那个数字。
I don't have an 8i database lying around any more (perhaps not surprisingly) but I don't recall ever needing to quote a cursor query;我不再有 8i 数据库了(也许并不奇怪),但我不记得曾经需要引用游标查询; and if you do I'm pretty sure the semicolon would need to be outside the closing quote.如果你这样做,我很确定分号需要在结束语之外。 But that was also what was causing the earlier line 4, column 5 error, which was pointing at that opening quote.但这也是导致前面第 4 行第 5 列错误的原因,该错误指向那个开头引用。
You will also try to insert the last value twice;您还将尝试两次插入最后一个值; you need to test C1%NOTFOUND
before the INSERT
, immediately after the FETCH
(unless you are using bulk collect).您需要在INSERT
之前测试C1%NOTFOUND
,在FETCH
之后立即测试(除非您使用批量收集)。 Of course you're inserting a dummy value, but you'll get one too many rows;当然,您插入的是一个虚拟值,但是您会得到太多行; with your real CLOB you'd process the last fetch value twice.使用您的真实 CLOB,您将处理最后一次提取值两次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.