SQLWARNING
SQLWARNING is a subclass of SQLException. It provides information on database access warnings. Warnings are issued by a database to indicate that no error occurred, but something unusual occurred that may be of interest or concern.
Example
Output
Explanation
The above SQL warning code block for Oracle declares a salary variable and assigns a value. Then it checks if the salary is greater than 5000. If it is, a warning message is outputted. It’s just a simple demonstration and SQL itself does not have a native SQLWARNING
mechanism similar to SQLException
, this way Oracle’s DBMS_OUTPUT.PUT()
function is used to simulate a warning message.
Example
Output
Explanation
The given SQL code block is an example of SQLWARNING. A TRY block is used to encapsulate a series of commands. The warning message ‘WARNING: Value exceeds limit’ prints if the maximum value from the specified column of a table is greater than a defined limit (1000 in this case). A CATCH block is provided to handle potential errors during execution. In this example, it will print ‘ERROR: An error occurred.’ if there’s an execution error. In a real-world application, additional error handling or appropriate responses could be added in the CATCH block.