<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to generate sequence numbers between two numbers</title>
	<atom:link href="http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/</link>
	<description>Oracle Question and Answer</description>
	<lastBuildDate>Wed, 29 Jul 2009 16:01:28 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: gamyers</title>
		<link>http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/comment-page-1/#comment-85</link>
		<dc:creator>gamyers</dc:creator>
		<pubDate>Wed, 25 Jan 2006 04:53:22 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/#comment-85</guid>
		<description>Like Laurent, I&#039;m not happy with the CONNECT BY/LEVEL solution.

This is a good alternative for 10G, and the MODEL clause is actually intended to generate rows.

&lt;pre&gt;
SELECT days
FROM (select 20 days from dual) mnth
MODEL
  DIMENSION BY (days)
  MEASURES (days v)
  RULES UPSERT
  (v[FOR days FROM 20 TO 26 INCREMENT 1] = 1)
order by 1
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Like Laurent, I&#8217;m not happy with the CONNECT BY/LEVEL solution.</p>
<p>This is a good alternative for 10G, and the MODEL clause is actually intended to generate rows.</p>
<pre>
SELECT days
FROM (select 20 days from dual) mnth
MODEL
  DIMENSION BY (days)
  MEASURES (days v)
  RULES UPSERT
  (v[FOR days FROM 20 TO 26 INCREMENT 1] = 1)
order by 1
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie Awad</title>
		<link>http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/comment-page-1/#comment-82</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Mon, 23 Jan 2006 19:00:04 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/#comment-82</guid>
		<description>&lt;i&gt;Laurent Schneider Says: Why do you need it?&lt;/i&gt;

A co-worker of mine asked me: &quot;Lets say I have a table with a numeric field (called x) and there are 3 records in that table and for those 3 records field x has a value of 22, 23, 25. I want to produce a report (sql select statement) that lists any number between 21 and 25 that is not on this table (ie the sql select statement should return 21 and 24 as a result set). The range (between 21 and 25) is a user input, and as a result can change with each run.&quot;

The above query can come in handy to solve such a problem:

&lt;pre&gt;
select *
    from (
        select (lvl + &amp;v_from - 1) mynum
            from (
                select *
                from (
                    select level lvl
                    from dual
                    connect by level &lt;= (&amp;v_to - &amp;v_from) + 1
                   )
               )
       )
   where mynum not in (select x from t)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p><i>Laurent Schneider Says: Why do you need it?</i></p>
<p>A co-worker of mine asked me: &#8220;Lets say I have a table with a numeric field (called x) and there are 3 records in that table and for those 3 records field x has a value of 22, 23, 25. I want to produce a report (sql select statement) that lists any number between 21 and 25 that is not on this table (ie the sql select statement should return 21 and 24 as a result set). The range (between 21 and 25) is a user input, and as a result can change with each run.&#8221;</p>
<p>The above query can come in handy to solve such a problem:</p>
<pre>
select *
    from (
        select (lvl + &#038;v_from - 1) mynum
            from (
                select *
                from (
                    select level lvl
                    from dual
                    connect by level < = (&#038;v_to - &#038;v_from) + 1
                   )
               )
       )
   where mynum not in (select x from t)
</pre>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/comment-page-1/#comment-80</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Mon, 23 Jan 2006 15:52:36 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/#comment-80</guid>
		<description>&lt;pre&gt;create table t(n number primary key);&lt;/pre&gt;
is better</description>
		<content:encoded><![CDATA[<pre>create table t(n number primary key);</pre>
<p>is better</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/comment-page-1/#comment-79</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Mon, 23 Jan 2006 15:50:35 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/#comment-79</guid>
		<description>I just could not resist telling this is a hack, because connect by without prior is illegal and should generate a loop.

Using &quot;from all_objects&quot; is a &quot;limiting move&quot;, because it is a slow view with a limited number of objects (maybe 500, maybe 50000, you do not know).

You can search my blog for examples, but my &quot;favorite&quot; approach is to say there is no such function. Why do you need it? Think of doing a table containing your elements, ex :

&lt;pre&gt;create table t(n number);
exec for i in 1..1000000 loop insert into t(n) values (i); end loop
commit;
select * from t where n between 20 and 26;
         N
----------
        20
        21
        22
        23
        24
        25
        26
&lt;/pre&gt;

well, the PL/SQL part could be tuned, but the SELECT part is extremly fast</description>
		<content:encoded><![CDATA[<p>I just could not resist telling this is a hack, because connect by without prior is illegal and should generate a loop.</p>
<p>Using &#8220;from all_objects&#8221; is a &#8220;limiting move&#8221;, because it is a slow view with a limited number of objects (maybe 500, maybe 50000, you do not know).</p>
<p>You can search my blog for examples, but my &#8220;favorite&#8221; approach is to say there is no such function. Why do you need it? Think of doing a table containing your elements, ex :</p>
<pre>create table t(n number);
exec for i in 1..1000000 loop insert into t(n) values (i); end loop
commit;
select * from t where n between 20 and 26;
         N
----------
        20
        21
        22
        23
        24
        25
        26
</pre>
<p>well, the PL/SQL part could be tuned, but the SELECT part is extremly fast</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mihajlo Tekic</title>
		<link>http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/comment-page-1/#comment-75</link>
		<dc:creator>Mihajlo Tekic</dc:creator>
		<pubDate>Sat, 21 Jan 2006 17:54:43 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/#comment-75</guid>
		<description>This is very nice solution it does not include any DDL activity.
Since now, I used one table where I have only sequential numbers, which I increased always when I needed bigger range.

Thanks,</description>
		<content:encoded><![CDATA[<p>This is very nice solution it does not include any DDL activity.<br />
Since now, I used one table where I have only sequential numbers, which I increased always when I needed bigger range.</p>
<p>Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie Awad</title>
		<link>http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/comment-page-1/#comment-73</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Fri, 20 Jan 2006 21:21:02 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/#comment-73</guid>
		<description>Maceyah, neat solution but is not very dynamic and it involves DDL.

For example, using your method, to get the sequence numbers between 20 and 26 (i.e. 20, 21, 22, 23, 24, 25 and 26 -- 7 ordered numbers in total), first you need to create a sequence with specific min and max values:

&lt;pre&gt;
create sequence myseq minvalue 1 maxvalue 7 cycle cache 6;

select myseq.nextval+19 ---- (from value - 1)
  from all_objects 
 where rownum &lt;=7 ---- (from - to + 1)
&lt;/pre&gt;

Note that in this example, the minvalue and the maxvalue &lt;b&gt;have to be&lt;/b&gt; 1 and 7 respectively (or 0 and 6), otherwise you may have numbers outside the range. So, if you have a different range you have to either create a new sequence or alter the existing one.</description>
		<content:encoded><![CDATA[<p>Maceyah, neat solution but is not very dynamic and it involves DDL.</p>
<p>For example, using your method, to get the sequence numbers between 20 and 26 (i.e. 20, 21, 22, 23, 24, 25 and 26 &#8212; 7 ordered numbers in total), first you need to create a sequence with specific min and max values:</p>
<pre>
create sequence myseq minvalue 1 maxvalue 7 cycle cache 6;

select myseq.nextval+19 ---- (from value - 1)
  from all_objects
 where rownum < =7 ---- (from - to + 1)
</pre>
<p>Note that in this example, the minvalue and the maxvalue <b>have to be</b> 1 and 7 respectively (or 0 and 6), otherwise you may have numbers outside the range. So, if you have a different range you have to either create a new sequence or alter the existing one.</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: maceyah</title>
		<link>http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/comment-page-1/#comment-70</link>
		<dc:creator>maceyah</dc:creator>
		<pubDate>Fri, 20 Jan 2006 20:29:21 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/01/20/how-to-generate-sequence-numbers-between-two-numbers/#comment-70</guid>
		<description>&lt;pre&gt;SQL&gt; create sequence seq1 minvalue 0 maxvalue 6 cycle cache 5;

Sequence created.

SQL&gt; select seq1.nextval+20 from all_objects where rownum &lt; 10;

SEQ1.NEXTVAL+20
---------------
             20
             21
             22
             23
             24
             25
             26
             20
             21

9 rows selected.
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<pre>SQL&gt; create sequence seq1 minvalue 0 maxvalue 6 cycle cache 5;

Sequence created.

SQL&gt; select seq1.nextval+20 from all_objects where rownum &lt; 10;

SEQ1.NEXTVAL+20
---------------
             20
             21
             22
             23
             24
             25
             26
             20
             21

9 rows selected.
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
