I have a cursor for inserting employee data from temp table to main table. I have a scenario in which first it will check if temp table department id is exist in main department table; if DeptId does not exist then don't insert employee and update ERR_MSG column in temp table. I am handling exception inside if condition after INSERT statement, but it is giving me an error like
Encountered symbol EXCEPTION when expecting one of the following : begin,end,case,else......
sample code is as below:-
DECLARE
--var list
BEGIN
OPEN ltempCur For
-- here i am selecting cols from temp table in variables
LOOP
FETCH ltempCur
INTO
--all the declared variables here
EXIT
WHEN ltempCur %NOTFOUND;
BEGIN
--select statement for checking if employee record exist in table
IF(lExist == 0) --if emloyee record not exist
THEN
begin
--check if dept exist in dept table if not exist then i have assigned zero to deptid variable in NO_DATA_FOUND exception
end;
IF(vardeptid > 0) --if condition for which i have mentioned in description
--Insert statement for employee
EXCEPTION
WHEN OTHERS
THEN
--handling exp
COMMIT;
END;
END IF; -- dept id check if end
--end loop -- close cursor
In above code, if I remove deptid IF ELSE condition then it is working fine, but with that IF condition it is giving error
EXCEPTIONsection withinIF.. END IF.UseRAISEstatement if you want to raise an user defined exception when a condition is satisfied.EXCEPTIONsection should be at the end of aBEGIN..ENDand can handle or re-raise required exceptions. - Kaushik NayakBEGIN insert ... EXECPTION ... END;- APC