![]() ![]() Finally, update the customer whose id is entered by the user with the new credit limit.Third, check if the input credit with the maximum credit, if the input credit is greater than the max, then raise the e_credit_too_high exception.Second, select maximum credit from the customers table using the MAX() function and assign this value to the l_max_credit variable.First, declare a user-defined exception e_credit_too_high and associates it with the error number -20001.Code language: SQL (Structured Query Language) ( sql ) if not, update credit limit UPDATE customers check if input credit is greater than the max credit L_credit customers.credit_limit%TYPE := &credit_limit īEGIN - get the meax credit limit SELECT MAX(credit_limit) L_customer_id customers.customer_id%TYPE := &customer_id L_max_credit customers.credit_limit%TYPE PRAGMA exception_init( e_credit_too_high, -20001 ) ![]() The following example illustrates how to declare a user-defined exception and associate it with an error code. PRAGMA EXCEPTION_INIT (exception_name, error_number) Ĭode language: SQL (Structured Query Language) ( sql ) Raising a user-defined exception example The entire syntax for declaring a user-defined exception is as follows: DECLARE And the message is a character string with a maximum length of 2,048 bytes. In this syntax, the error_code is an integer that ranges from -20,999 to -20,000. To do it, you use the EXCEPTION_INIT pragma as follows: PRAGMA EXCEPTION_INIT (exception_name, error_code) Similar to the variable declaration, you declare an exception in the declaration section of a block.Ī user-defined exception must have assigned error_code. To define a user-defined exception, you use the following syntax: DECLAREĬode language: SQL (Structured Query Language) ( sql ) The RAISE statement allows you to:Ī user-defined exception is defined by users like you or other developers in the declaration section of a block or subprogram. To raise an exception explicitly, you use the RAISE statement. Summary: in this tutorial, you will learn how to use the PL/SQL RAISE statement to raise a user-defined exception, internally defined exception, and reraising an exception. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |