Select inside a cursor-loop [message #40829] |
Thu, 07 November 2002 09:07 |
Fall
Messages: 4 Registered: November 2002
|
Junior Member |
|
|
Hi List!,
I have this code:
------------------------
CREATE OR REPLACE PROCEDURE TEST IS
CURSOR C_datos is
<... some stuff in here ...>
Ln_tipo_id table1.cod_type_id%TYPE;
Ln_num_id table1.id_num%TYPE;
reg_paso C_datos%ROWTYPE;
SQL_MSG VARCHAR2 (100);
BEGIN
FOR reg_paso in C_datos LOOP
IF(reg_paso.FIELD4 is not null) THEN
Begin
SELECT field1, field2
INTO Ln_tipo_id, Ln_num_id
FROM table1
WHERE field3 = reg_paso.ANY_FIELD;
EXCEPTION
WHEN NO_DATA_FOUND THEN
Ln_tipo_id := reg_paso.FIELD1;
Ln_num_id := reg_paso.FIELD2;
END;
ELSE
Ln_tipo_id := reg_paso.FIELD1;
Ln_num_id := reg_paso.FIELD2;
END IF;
<... Some lines goes in here ...>
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('RollBack');
SQL_MSG := SUBSTR(SQLERRM,1,100);
dbms_output.put_line(SQL_MSG);
ROLLBACK;
END;
-------------------------
Now, the problem is that if I perform the select that is inside the If clause the result is 1 line, so, there wouldn't be any problem for that SELECT INTO. But, if I run the procedure TEST it always goes through the EXCEPTION NO_DATA_FOUND. The tables has been already granted to PUBLIC but I still have the same behavior.
Maybe is something too obvious, but I really need help on this.
Thanks in advance.
|
|
|
|
Re: Select inside a cursor-loop [message #40845 is a reply to message #40843] |
Thu, 07 November 2002 10:39 |
Fall
Messages: 4 Registered: November 2002
|
Junior Member |
|
|
Thanks Todd,
I replaced the EXEPTION clause in the IF THEN statement with this:
DBMS_OUTPUT.PUT_LINE('ANY_FIELD: '||reg_paso.ANY_FIELD);
And I run the select manually with the values given by that code, and the querys gives me 1 row each. If you need the complete code, tables and info, them could be provided.
Thanks again,
FALL
|
|
|
Re: Select inside a cursor-loop [message #40849 is a reply to message #40845] |
Thu, 07 November 2002 12:09 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
I would recommend running a query something like this that will identify any rows in your cursor that do not have a match in table1:
select *
from (your_cursor_query) c
where field4 is not null
and not exists (select null
from table1 t1
where t1.field3 = c.any_field);
|
|
|
|
|