title: Oracle WITH DELETE by row number
body: <p>I am writing a procedure which removes old rows by their viewed date:</p>
  
  <pre><code>;WITH pv AS (
      SELECT
          RN = ROW_NUMBER() OVER (ORDER BY viewed DESC)
      FROM
          previouslyViewed
      WHERE
          userId = @userId
  )
  DELETE FROM pv WHERE RN &gt;= 10
  </code></pre>
  
  <p>This works in SQL Server, but not in Oracle.</p>
  
  <p>Oracle doesn't support the WITH DELETE combination. Nor does it support the DELETE ORDER BY combination (which could theoretically be used with rownum to achieve the same result). I have tried to create a temporary view with the rownum and delete from that, but I get an Oracle error - seemingly you cannot delete from a view when rownum is used.</p>
  
  <p>Does anyone have any pointers?</p>