Returning results from procedures
248
When a
SELECT
statement is executed, the server retrieves the results of the
SELECT
statement and places the results in the variables. If the query results
contain more than one row, the server returns an error. For queries returning
more than one row, cursors must be used. For information about returning
more than one row from a procedure, see “Returning result sets from
procedures”.
If the query results in no rows being selected, a
row not found
warning is returned.
The following procedure returns the results of a single-row SELECT statement
in the procedure parameters.
To return the number of orders placed by a given customer, type the following:
CREATE PROCEDURE OrderCount (IN customer_ID INT,
OUT Orders INT)
BEGIN
SELECT COUNT(DBA.sales_order.id)
INTO Orders
FROM DBA.customer
KEY LEFT OUTER JOIN DBA.sales_order
WHERE DBA.customer.id = customer_ID;
END
You can test this procedure in DBISQL using the following statements, which
show the number of orders placed by the customer with ID 102:
CREATE VARIABLE orders INT;
CALL OrderCount ( 102, orders );
SELECT orders;
Notes
•
The customer_ID parameter is declared as an IN parameter. This
parameter holds the customer ID that is passed in to the procedure.
•
The Orders parameter is declared as an OUT parameter. It holds the value
of the orders variable that is returned to the calling environment.
•
No DECLARE statement is required for the Orders variable, as it is
declared in the procedure argument list.
•
The SELECT statement returns a single row and places it into the variable
Orders.
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 ...