简体   繁体   中英

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. I have read in the oracle forums that PL/SQL 8i doesn't support subscalar queries.

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?

The PLS-00103 is telling you where the problem is; line 6 column 49. In this part of your query:

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; 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.

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM