Oracle VS MS SQL-RowNUM

摘要:Oracle VS MS SQL-RowNUM

Oracle本身有提供RowNum可以使用,而MS SQL到SQL 2005也加入類似的函數,不過,哈..MS SQL一直有的Top功能也很好用...

接下來來比較一下二種廠牌在實際要取得資料時的做法,其實真的..大同小異

 因為要依排序的方式取得,所以都先取出來再去下Where RowNum的條件,Oracle查到的資料,似乎RowNum是先產生再做Order by,若有誤煩請指教~

經大大指教後才發現,原來二種廠版用法一樣嘛...同樣都用Rown_Number()  Over()做

Oracle      

         Select a.* From

                       (

                           Select  ROW_NUMBER() OVER(ORDER BY Col3 ) RowNum,Col1,Col2 from TableName

                       )   where Col1  between 30 and 40

MS SQL

         Select a.* From

                       (

                           Select Top 100 percent ROW_NUMBER() OVER(ORDER BY Col3 ) RowNum,Col1,Col2 from TableName

                       ) as a  where a.Col1  between 30 and 40

打雜打久了,就變成打雜妹

程式寫久了,就變成老乞丐