Chapter 9 SQL Statements
545
IF statement
Use this statement to control conditional execution of SQL statements.
IF
search-condition
THEN
statement-list
… [ ELSEIF
search-condition
THEN
statement-list
] …
… [ ELSE
statement-list
]
… END IF
None.
None.
"BEGIN statement" on page 404
"Using Procedures, Triggers, and Batches" on page 435 of the book ASA
User’s Guide
The IF statement is a control statement that allows you to conditionally
execute the first list of SQL statements whose search-condition evaluates to
TRUE. If no search-condition evaluates to TRUE, and an ELSE clause
exists, the statement-list in the ELSE clause is executed.
Execution resumes at the first statement after the END IF.
IF statement is different from IF expression
Do not confuse the syntax of the IF statement with that of the IF
expression.
$ For information on the IF expression, see "IF expressions" on
page 232.
♦ SQL/92 Persistent Stored Module feature.
♦
Sybase The Transact-SQL IF statement has a slightly different syntax.
♦ The following procedure illustrates the use of the IF statement:
CREATE PROCEDURE TopCustomer (OUT TopCompany
CHAR(35), OUT
TopValue INT)
BEGIN
DECLARE err_notfound EXCEPTION
FOR SQLSTATE ’02000’;
DECLARE curThisCust CURSOR FOR
SELECT company_name, CAST(
sum(sales_order_items.quantity *
product.unit_price) AS INTEGER) VALUE
FROM customer
LEFT OUTER JOIN sales_order
LEFT OUTER JOIN sales_order_items
Function
Syntax
Permissions
Side effects
See also
Description
Standards and
compatibility
Example