title: I would like to add a unique constraint onto a column. Before running an upgrade, check to see if however that column has duplicate values
body: <p>This is fine:</p>
  <pre><code>ALTER TABLE tableName
  ADD CONSTRAINT conName UNIQUE (columnName);
  </code></pre>
  <p>However, I can't seem to get the following to work:</p>
  <pre class="lang-sql prettyprint-override"><code>DECLARE
      ln_count NUMBER(5) := 0;
  BEGIN
      SELECT
      COUNT(*) AS cnt 
  INTO
      ln_count
  FROM
      tableName
  GROUP BY
      columnName
  WHERE --change to Having, receive ORA-00905: missing keyword error 
      COUNT(*) &gt; 1;
  
  IF (ln_count &gt;= 0) THEN
  --code to stop upgarde script
  END IF;
  END;
  </code></pre>
  <p>Any different way of doing this would also be welcome. However, I am trying to get it to work on both Oracle and PostgreSQL any solution that will solve at least one is already a step forward.</p>
  <pre><code>SELECT COUNT(*)
  FROM OrderDetails
  GROUP BY OrderId
  HAVING COUNT(*) &gt; 1;
  </code></pre>
  <p>Output: <a href="https://i.stack.imgur.com/fDHRk.png" rel="nofollow noreferrer">output of query</a>
  I want to have something similar to the above but have my answer in a variable to be used in order to check if duplicates exists.</p>