CHAPTER 6 Using Procedures and Batches
255
AS ThisValue
FROM customer
INNER JOIN sales_order
INNER JOIN sales_order_items
INNER JOIN product
GROUP BY ThisName
DO
IF ThisValue > TopValue THEN
SET TopCompany = ThisName;
SET TopValue = ThisValue;
END IF;
END FOR CompanyLoop;
END
Errors and warnings in procedures
After an application program executes a SQL statement, it can examine a
return code. This return code indicates whether the statement executed
successfully or failed and gives the reason for the failure. The same mechanism
can be used to indicate the success or failure of a CALL statement to a
procedure.
Error reporting uses either the SQLCODE or SQLSTATE status descriptions.
Whenever a SQL statement is executed, a value is placed in special procedure
variables called SQLSTATE and SQLCODE. That value indicates whether or
not there were any unusual conditions encountered while the statement was
being performed. You can check the value of SQLSTATE or SQLCODE in an
IF statement following a SQL statement, and take actions depending on
whether the statement succeeded or failed.
For example, the SQLSTATE variable can be used to indicate if a row is
successfully fetched. The
TopCustomerValue
procedure presented in section
“Using cursors on SELECT statements in procedures” used the SQLSTATE
test to detect that all rows of a SELECT statement had been processed.
For full descriptions of SQLCODE and SQLSTATE error and warning values
and their meanings, see “Database Error Messages” in Adaptive Server IQ
Reference Manual.
Summary of Contents for Adaptive Server IQ 12.4.2
Page 1: ...Administration and Performance Guide Adaptive Server IQ 12 4 2 ...
Page 16: ...xvi ...
Page 20: ...Related documents xx ...
Page 40: ...Compatibility with earlier versions 20 ...
Page 118: ...Troubleshooting startup shutdown and connections 98 ...
Page 248: ...Importing data by replication 228 ...
Page 306: ...Integrity rules in the system tables 286 ...
Page 334: ...Cursors in transactions 314 ...
Page 396: ...Users and permissions in the system tables 376 ...
Page 438: ...Determining your data backup and recovery strategy 418 ...
Page 484: ...Network performance 464 ...
Page 500: ...System utilities to monitor CPU use 480 ...
Page 514: ...Characteristics of Open Client and jConnect connections 494 ...
Page 536: ...Index 516 ...