title: DB2 trigger definition
body: <p>I'm trying to create DB2 trigger which is using the procedure <code>VOTES_COUNT</code> but when I try to create the trigger I get the error: </p>
  
  <blockquote>
    <p>An unexpected token "" was found following "".  Expected tokens may
    include:  "SET status = 1".. SQLCODE=-104, SQLSTATE=42601,
    DRIVER=4.7.89</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>CREATE PROCEDURE VOTES_COUNT (IN username VARCHAR(15), OUT votesCount INT)
  DYNAMIC RESULT SETS 1
  
  P1: BEGIN
  
  DECLARE C1 CURSOR FOR 
      SELECT COUNT(*) AS R1
          FROM VOTES
          WHERE USER = username;
  OPEN C1;    
  FETCH C1 INTO votesCount;   
  CLOSE C1;
  
  END P1 @
  
  CREATE TRIGGER UPDATE_LEVEL
  AFTER INSERT ON VOTES
  REFERENCING NEW AS N
  FOR EACH ROW
  BEGIN ATOMIC
      DECLARE num INT;
      DECLARE status INT;
      CALL VOTES_COUNT(N.USERNAME, num);
      CASE
          WHEN num &gt;= 300 
              THEN SET status = 5;
          WHEN num &lt; 300 AND num &gt;= 200
              THEN SET status = 4;
          WHEN num &lt; 200 AND num &gt;= 100
              THEN SET status = 3;
          WHEN num &lt; 100 AND num &gt;= 50
              THEN SET status = 2;
          ELSE
              SET status = 1;
      END CASE;
      UPDATE USERS SET STATUS = status WHERE USERNAME = N.USERNAME;
  END @
  </code></pre>
  
  <p>Can you tell me what I'm doing wrong?</p>