yajesh
asked on
BEGIN....END within IF......END IF Construct
Can you have several BEGIN.....END constructs within a single IF.....END IF? Would it be wise to insert an EXCEPTION Handler within each BEGIN.....END.
For Example:
IF........................ THEN -- Start
BEGIN
NULL;
END;
BEGIN
NULL;
END;
BEGIN
NULL;
END;
END IF; -- End
Yaj
For Example:
IF........................
BEGIN
NULL;
END;
BEGIN
NULL;
END;
BEGIN
NULL;
END;
END IF; -- End
Yaj
You would need to surround all of the inner block in it's own BEGIN - IF like this:
IF ...
BEGIN
BEGIN
NULL;
END;
BEGIN
NULL;
END;
BEGIN
NULL;
END;
END IF;
IF ...
BEGIN
BEGIN
NULL;
END;
BEGIN
NULL;
END;
BEGIN
NULL;
END;
END IF;
knightEknight, it isn't necessary to surround the individual blocks with a BEGIN and END. The syntax supplied by vajesh will work.
ASKER
A very valid question, Milleniumaire.
First of all I am newbie to PL/SQL, still learning tricks of the trade.
In my IF. THEN...............END IF construct, I have few SELECT followed by UPDATE statements. Say for example I have 3 groups of SELECT....INTO respective variables with its own WHERE criteria followed by UPDATE another TABLE based on SELECT statement.
So my code would look something like this:
IF ................ THEN
SELECT.................
UPDATE
SELECT...................
UPDATE
etc..
etc..
END IF;
So I was thinking if I can use BEGIN....END within each SELECT....UPDATE group, then I mighty be able to insert ECEPTION Handles for each group withion each BEGIN.... END, instead of single EXCEPTION Handler before END IF.
yaj
First of all I am newbie to PL/SQL, still learning tricks of the trade.
In my IF. THEN...............END IF construct, I have few SELECT followed by UPDATE statements. Say for example I have 3 groups of SELECT....INTO respective variables with its own WHERE criteria followed by UPDATE another TABLE based on SELECT statement.
So my code would look something like this:
IF ................ THEN
SELECT.................
UPDATE
SELECT...................
UPDATE
etc..
etc..
END IF;
So I was thinking if I can use BEGIN....END within each SELECT....UPDATE group, then I mighty be able to insert ECEPTION Handles for each group withion each BEGIN.... END, instead of single EXCEPTION Handler before END IF.
yaj
What you mention is the exact reason to have the ability to nest PL/SQL blocks: The ability to trap and handle exceptions with a local scope.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, Milleniumaire,
I understand it better now.
Further to that, I was also able to find additional details, that is also most probably in line with your suggestion too.
http://www.java2s.com/Tutorial/Oracle/0480__PL-SQL-Programming/AcompleteexampleusingRAISEAPPLICATIONERROR.htm
yaj
I understand it better now.
Further to that, I was also able to find additional details, that is also most probably in line with your suggestion too.
http://www.java2s.com/Tutorial/Oracle/0480__PL-SQL-Programming/AcompleteexampleusingRAISEAPPLICATIONERROR.htm
yaj
Why do you need to have multiple blocks? Usually, this is necessary to code for specific exceptions. Is this the case for you?