Skip to content

Instantly share code, notes, and snippets.

@arbo-hacker
Created March 8, 2016 20:34
Show Gist options
  • Save arbo-hacker/6f5dc65e7b8e93d91277 to your computer and use it in GitHub Desktop.
Save arbo-hacker/6f5dc65e7b8e93d91277 to your computer and use it in GitHub Desktop.
Clausulas de limitación para ’SQL Row'
create table nums as
select level as num from dual
connect by level <= 100;
-- Table created.
select count(1) as cnt from nums;
-- CNT
-- ------------
-- 100
select num from nums
order by 1 desc
fetch first 10 rows only;
-- NUM
-- ------------
-- 100
-- 99
-- 98
-- 97
-- 96
-- 95
-- 94
-- 93
-- 92
-- 91
select num from nums
order by 1
fetch first 12 percent rows only;
-- NUM
-- ------------
-- 1
-- 2
-- 3
-- 4
-- 5
-- 6
-- 7
-- 8
-- 9
-- 10
-- 11
-- 12
select num from nums
order by 1
offset 4 rows fetch next 6 rows only;
-- NUM
-- ------------
-- 5
-- 6
-- 7
-- 8
-- 9
-- 10
select num from nums
order by 1
offset 2 rows fetch next 15 percent rows only;
-- NUM
-- ------------
-- 3
-- 4
-- 5
-- 6
-- 7
-- 8
-- 9
-- 10
-- 11
-- 12
-- 13
-- 14
-- 15
-- 16
insert into nums select * from nums;
-- 10 rows inserted
commit;
select count(1) as cnt from nums;
-- CNT
-- ----------
-- 200
select num from nums
order by 1 desc
fetch first 7 rows with ties;
-- NUM
-- ------------
-- 100
-- 100
-- 99
-- 99
-- 98
-- 98
-- 97
-- 97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment