END
END is a keyword in SQL that signifies the conclusion of a control flow block, such as the termination point of a BEGIN...END compound statement, an IF...ELSE statement, or a CASE statement. It plays an essential role in structuring the SQL script and defining the sections of code that form a single procedure or command. It ensures the correct sequence of SQL operations.
Example
Output
Explanation
The given SQL code demonstrates a stored procedure in MySQL named productpricing
. This procedure uses a cursor to loop through all products in the products
table. Using the IF
statement, it categorizes each product as ‘High’ if its price is greater than 100, or ‘Low’ otherwise. The END IF
marks the end of the IF
control structure, whereas END LOOP
indicates the end of the LOOP
structure. Lastly, END
signifies the end of the procedure.
The output displays the names and price categories of each product after calling the productpricing
procedure.
Example
Output
Explanation
The CASE
statement iterates over the conditions until it finds one that is true. Since the @PersonAge
in this example has been set to 18, the output is ‘Teenager’.
Output
Explanation
The provided PL/SQL block declares a variable a
, then checks if a
is greater than 20. The IF
conditional statement evaluates the condition, and depending on whether the result is true or false, it executes the corresponding branch. Since a
is 10 which is not greater than 20, it executes the ELSE
block and prints ‘a is not greater than 20’. The END
keyword indicates the end of the IF
statement and the anonymous block.