Wouldn't the ROW_NUMBER analytic function in an inline view do the trick?