{"id":6680,"date":"2020-07-07T21:20:05","date_gmt":"2020-07-08T02:20:05","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=6680"},"modified":"2020-07-07T23:08:19","modified_gmt":"2020-07-08T04:08:19","slug":"oracle-select-top","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=6680","title":{"rendered":"Oracle &#8211; Select Top"},"content":{"rendered":"<p>I discovered the &#8220;rownum&#8221; trick early in my usage of Oracle databases &#8212; especially useful for sampling data to see what&#8217;s in there, something like &#8220;select * from dataTable where rownum &lt; 6&#8221; gets you the first five records. <em>But<\/em> that&#8217;s not suitable if you want to sort the records. In this particular case, I have a series of names. I want to find the highest number value in the series so I can name my object with the next sequential name.<\/p>\n<p>Enter &#8220;fetch first&#8221;\u00a0 &#8230; this appears to be available since 12c (so older database installations may still require a more convoluted solution):<\/p>\n<pre>SELECT set_name from set_data\r\nWHERE set_name LIKE 'Something-With-A-Series-%'\r\nORDER BY set_name DESC\r\nfetch first 1 row only;<\/pre>\n<p>Which returns the <em>last<\/em> name in the series.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I discovered the &#8220;rownum&#8221; trick early in my usage of Oracle databases &#8212; especially useful for sampling data to see what&#8217;s in there, something like &#8220;select * from dataTable where rownum &lt; 6&#8221; gets you the first five records. But that&#8217;s not suitable if you want to sort the records. In this particular case, I &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1004],"tags":[595,922],"class_list":["post-6680","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-oracle","tag-sql"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6680"}],"version-history":[{"count":2,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6680\/revisions"}],"predecessor-version":[{"id":6682,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/6680\/revisions\/6682"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}