DUP_VAL_ON_INDEX This is bit different from the above two exceptions. This exception is not at all related to SELECT..INTO statement (as above exceptions). This exception gets raised when you try to update (or even insert) a row with a duplicate value in to a column constrained by a unique index (obviously Primary key as well). Let us consider the following program. Declare The flow of execution of program will be something like the following:
ZERO_DIVIDE, INVALID_NUMBER, VALUE_ERROR The above two predefined exceptions worked well with SELECT..INTO statement. But some predefined exceptions may not be related to SELECT..INTO statement. Let us see ZERO_DIVIDE, INVALID_NUMBER and VALUE_ERROR together within this section. No number can be divided with zero as it results in infinite. To handle such type of situation, there exists ZERO_DIVIDE exception. Let us consider the following example. Declare The above program illustrates simple variable declarations of numeric data type. Here, we declare three variables (x, y and z). The values of variables 'x' and 'y' are accepted from the user. Observe that all the variables are of type number (any numeric data type is acceptable). Within the body, we divide 'x' with 'y' and store the result in 'z'. Everything works fine as long as you provide proper values. If you try to provide the value of 'y' as zero, then ZERO_DIVIDE exception gets raised and a message gets displayed to user. Coming to INVALID_NUMBER, I hope you can easily understand that whenever PL/SQL runtime is unable to convert a character string to number, the exception gets raised. The following example demonstrates the same. Declare Coming to VALUE_ERROR, this is almost similar to INVALID_NUMBER except that it works with almost any data type. INVALID_NUMBER gets raised only when SQL statement is issued whereas VALUE_ERROR gets raised with PL/SQL statements. Let us go through the following example. Declare The above program accepts the value of 'x' and 'y' in the form of character strings and implicitly converts them to numeric. If user provides a non-numeric value, the VALUE_ERROR gets raised. In this case, INVALID_NUMBER will not be raised as nothing is related with SQL statement.
blog comments powered by Disqus |