Error number -746 allows you to provide the text of the error message. Like the preceding example, the following one also generates an error if new_qty is greater than old_qty multiplied by 1.50. However, in this case the error number is -746, and the message text Too many items for Mfr. is supplied as the third argument in the RAISE EXCEPTION statement. For more information on the syntax and use of this statement, see the RAISE EXCEPTION statement in Creating and Using SPL Routines.
CREATE PROCEDURE upd_items_p2() DEFINE GLOBAL old_qty INT DEFAULT 0; DEFINE new_qty INT; LET new_qty = (SELECT SUM(quantity) FROM items); IF new_qty > old_qty * 1.50 THEN RAISE EXCEPTION -746, 0, 'Too many items for Mfr.'; END IF END PROCEDURE;
If you use DB–Access to submit the triggering statement, and if new_qty is greater than old_qty, you will get the result that Figure 475 shows.
Press CTRL-W for Help SQL: New Run Modify Use-editor Output Choose Save Info Drop Exit Modify the current SQL statements using the SQL editor. -------------------- store7@myserver --------- Press CTRL-W for Help ----- INSERT INTO items VALUES( 2, 1001, 2, 'HRO', 1, 126.00); 746: Too many items for Mfr.
If you invoke the trigger through an SQL statement in an SQL API, the database server sets sqlcode to -746 and returns the message text in the sqlerrm field of the SQL communications area (SQLCA). For more information about how to use the SQLCA, see your SQL API manual.
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]