BEGIN ... END

From InterBase
Jump to: navigation, search

Go Up to Procedures and Triggers


Defines a block of statements executed as one. Available in triggers and stored procedures.

<block> =
 BEGIN
  <compound_statement> 
 [<compound_statement> <>]
 END
<compound_statement> = {<block> | statement;}

Description: Each block of statements in the procedure body starts with a BEGIN statement and ends with an END statement. As shown in the above syntax diagram, a block can itself contain other blocks, so there may be many levels of nesting.

BEGIN and END are not followed by a semicolon. In isql, the final END in the procedure body is followed by the semicolon.

The final END statement in a trigger terminates the trigger. The final END statement in a stored procedure operates differently, depending on the type of procedure:

  • In a select procedure, the final END statement returns control to the application and sets SQLCODE to 100, which indicates there are no more rows to retrieve.
  • In an executable procedure, the final END statement returns control and current values of output parameters, if any, to the calling application.

Example: The following isql fragment of the DELETE_EMPLOYEE procedure shows two examples of BEGINEND blocks.

CREATE PROCEDURE DELETE_EMPLOYEE (EMP_NUM INTEGER)
AS
DECLARE VARIABLE ANY_SALES INTEGER;
BEGIN
ANY_SALES = 0;
. . .
IF (ANY_SALES > 0) THEN
BEGIN
EXCEPTION REASSIGN_SALES;
EXIT;
END
. . .
END
;

See Also

Advance To: