Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

No Data Found in SELECT INTO

693765Feb 25 2010 — edited Feb 25 2010
Hi all,

I try to select into a variable in a cursor loop but I get NO DATA FOUND when
the select doesn't return a value.
I want to set the variable to be 0 when the select fails.

I tried to add an exception but I get the following:

ORA-00900: invalid SQL statement


Here is the code I'm trying to execute (The exception is commented):

Line: -----
PROCEDURE MyProc IS
v_op NUMBER;
BEGIN

FOR cursor1 IN (select * from myTable)
LOOP
SELECT operation INTO v_op FROM operationsTable where id=cursor1.ID;


--EXCEPTION*
-- WHEN NO_DATA_FOUND THEN
-- v_op :=0;

--END;*

END LOOP;
END MyProc ;
Line: -----

Does anybody know how to set a variable when the select fails with NO DATA FOUND?
Thanks
dyahav
This post has been answered by Tubby on Feb 25 2010
Jump to Answer

Comments

388131
First of all I would reconsider if you really need to create a trigger inside a procedure. Question the reason...
Then, if you really need to do create it that way, you could try dynamic sql.
Ludock
This trigger have to be on all tables.

After creation a table, i call the procedure to generate the trigger.
388131
Well, then proceed with dynamic SQL.

Or, in my opinion much better: produce a SQL script with variables for table name and trigger name.
Then run this script with the appropriate values every time you have created a table.

Cheers,
Guido

Edited by: Guido on Oct 22, 2008 10:30 AM
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 25 2010
Added on Feb 25 2010
5 comments
340,007 views