exceptions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

exceptions [2015/09/23 20:27] (current)
Line 1: Line 1:
 +====== Exceptions - PL/HQL Reference ======
  
 +PL/HQL allows you to handle exceptions in your programs. ​
 +
 +**Syntax:**
 +
 +<code language=sql>​
 +BEGIN
 +  -- Statements that can raise an exception
 +EXCEPTION
 +  WHEN condition THEN 
 +    -- Statements
 +  WHEN condition2 THEN
 +    -- Statements2
 +    ...
 +END
 +</​code>​
 +
 +**Example**:​
 +
 +<code language=sql>​
 +DECLARE ​
 +  v VARCHAR(200);​
 +BEGIN
 +  OPEN cur FOR '​SELECT c1 FROM t1';
 +  FETCH cur INTO v;
 +  CLOSE cur;
 +EXCEPTION WHEN OTHERS THEN
 +  DBMS_OUTPUT.PUT_LINE('​Error'​);​
 +END
 +</​code>​
 +
 +**Compatibility**:​ Oracle, PostgreSQL and Netezza.