Cursor- no data found exception handaling [message #417131] |
Thu, 06 August 2009 04:39  |
mahantesh
Messages: 28 Registered: March 2008 Location: Mumbai ,India
|
Junior Member |
|
|
In my procedure there are three cursor
cur_customer_details
cur_revenue_details
cur_cost_details.
I have problem with cursor cur_cost_details.
Here select statement fetches some rows and i insert these record in to database table.
But when select statement returns no row then i want to insert some other data in to database table.
To get this result i try by using insert command in no data found exception but it is of no use. so i have try with some user defind exception , but it is also not of use.
here i have added code
MOD-EDIT: Removed Unnecessary Code that was breaking the board.
So can anyone help me regarding this.
Thanks
Mahantesh
[Updated on: Thu, 06 August 2009 04:43] by Moderator Report message to a moderator
|
|
|
Re: Cursor- no data found exception handaling [message #417133 is a reply to message #417131] |
Thu, 06 August 2009 04:47   |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
I removed the code because it served no real purpose to explain the problem, and it broke the board in a way that the reply-buttons where about six screens to the left.
A cursor that returns no rows will NOT raise an exception, so you can't implement your requirement with exception handling.
You need to use a variable or something in the code that processes the returned rows to check if rows are returned or not.
[Updated on: Thu, 06 August 2009 04:57] Report message to a moderator
|
|
|
|
|
|
Re: Cursor- no data found exception handaling [message #417145 is a reply to message #417139] |
Thu, 06 August 2009 05:03   |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
Quote: |
A cursor that returns no rows will NOT raise an exception, so you can't implement your requirement with exception handling.
|
You have to check after the loop if any rows were returned. This would be a possible way to do it.
DECLARE
v_rows_returned number;
BEGIN
v_rows_returned := 0;
FOR l IN (SELECT 1 FROM dual WHERE 1 = 1) LOOP
v_rows_returned := v_rows_returned + 1;
END LOOP;
Dbms_Output.put_line('Rows Returned : ' || v_rows_returned);
v_rows_returned := 0;
FOR l IN (SELECT 1 FROM dual WHERE 1 = 2) LOOP
v_rows_returned := v_rows_returned + 1;
END LOOP;
Dbms_Output.put_line('Rows Returned : ' || v_rows_returned);
END;
/
|
|
|
|
|
|
|
|
|
|