Oracleã§limit offsetãã©ã
postgreSQLã«ã¯limit offsetãããæã«ã¯é常ã«ä¾¿å©ãªæ©è½ã
Oracleã®å ´åãROWNUMã使ã£ã¦ä¼¼ããããªäºãåºæ¥ã¾ãã
Oracleã«ããã¦ãHOGEãã¼ãã«ã®æ¤ç´¢çµæã®ä¸ããæåã®10件ãåå¾ãããå ´åã¯
select * from HOGE where rownum <= 10;
ã¾ãã¯
select * from HOGE where rownum between 1 and 10;
ã¨ãã¾ããããã¯ä¸è¬çã«ãã使ãããæ¹æ³ã¨æãã¾ãã
ã§ã¯ã10件ç®ãã5件åå¾ãããã¨ãªã£ãå ´åã¯ã©ãã§ãããã
ä¸è¨ã¨åãããã«
select * from HOGE where rownum between 10 and 15;
ã¾ãã¯
select * from HOGE where 10 <= rownum and rownum <= 15;
ã¨ããã°è¯ãã®ã§ã¯ï¼ã¨æãã¾ãããå®éã¯æå³ããçµæãå¾ããã¾ããã
ãã®SQLã ã¨ãæåã«fetchããã1è¡ç®ãROWNUM 1ã¨ãªã
WHEREå¥å
ã®æ¡ä»¶ãæºããããªãçºã«ãåå¾å¯¾è±¡å¤ã¨ãªãã¾ãã
Oracleã§limit offsetãã©ããè¡ãã«ã¯ä»¥ä¸ã®ããã«ãã¦åå¾ãã¾ãã
# HOGEãã¼ãã«ã«ã¯name, ageã«ã©ã ãããã¨ãã¾ã
select name, age from (select name, age, rownum as rn from HOGE) where 10 <= rn and rn <= 15;
ãããã¯
select name, age from (select name, age, rownum as rn from HOGE) where rn between 10 and 15;
ã¤ã¾ãå¯åãåããã«ãã£ã¦ROWNUMã確å®ããã¦ããã¦ãã
ç¯å²æå®ãã¦ãã¼ã¿ãåå¾ããã¨ããæ¹æ³ã§ããã
ã¡ããã©manholeããã¨ãã§limit offsetã®è©±ãã
ãã£ãã®ã§ãé¢ä¿ç¡ãã§ããã³ãã¿ã¨ãã¦(^^