Error executing Cursor

0

When I execute the next SQL block, it tells me that I must declare the variable p_name, but I have declared it before.

declare
p_nombre varchar2(200) ;
BEGIN

    FOR REG IN (select c1000 INTO p_nombre 
        from edyficar.cl_clientes2 
        where cod_seg_mor = 1 and cod_seg_cob = 9 and c8421 = 'S' and segmentacion = 'C1' )
    LOOP
        dbms_output.put_line(REG.p_nombre);
    END LOOP;
END;
    
asked by Carlos Cortez 17.04.2017 в 07:39
source

2 answers

1

Try with:

DECLARE
CURSOR cursor_nombre is 
    select c1000 
    from edyficar.cl_clientes2 
    where cod_seg_mor = 1 
    and cod_seg_cob = 9 
    and c8421 = 'S' 
    and segmentacion = 'C1';
BEGIN
    FOR REG IN cursor_nombre
    LOOP
        dbms_output.put_line(REG.c1000);
    END LOOP;
END;
    
answered by 17.04.2017 в 12:28
1

The error is due to reg.p_nombre that you have not declared. Actually, the problem is that you are trying to use the implicit cursor syntax (very well), but mixing it with the syntax of SELECT ... INTO (bad).

The correct way to use the implicit cursors is the following (note that in the correct way, you do not even need to declare the variable p_nombre :

BEGIN
    FOR REG IN (select c1000
        from edyficar.cl_clientes2 
        where cod_seg_mor = 1 and cod_seg_cob = 9 and c8421 = 'S' and segmentacion = 'C1' )
    LOOP
        dbms_output.put_line(REG.c1000);
    END LOOP;
END;
    
answered by 17.04.2017 в 12:48