<?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 find missing values in a sequence with SQL</title>
	<atom:link href="http://www.xaprb.com/blog/2005/12/06/find-missing-numbers-in-a-sequence-with-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xaprb.com/blog/2005/12/06/find-missing-numbers-in-a-sequence-with-sql/</link>
	<description>Stay curious!</description>
	<lastBuildDate>Sat, 13 Mar 2010 17:09:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mohammed Kassab</title>
		<link>http://www.xaprb.com/blog/2005/12/06/find-missing-numbers-in-a-sequence-with-sql/#comment-17799</link>
		<dc:creator>Mohammed Kassab</dc:creator>
		<pubDate>Thu, 11 Feb 2010 07:35:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=57#comment-17799</guid>
		<description>Dear Para,
-----------------------------------
I created a table named [xparb] containing 5 rows [2,4,5,6,8]. Run the code below:
-----------------------------------
declare
k   number(6) := 1; /* counter to count the number of unused serials [i just used k for Kassab] */
cursor crs1 is
 select seq,LAG(seq, 1, 0) OVER (ORDER BY seq) AS seq_prev
 from   xparb; /* cursor to fetch all sequences in xparb table */
cnt number; /* total count of sequences in our e.g. = 2,4,5,6,8 */
v_seq1 number(5);
v_seq2 number(5);
v_diff number(5);
begin
 select count(*) into cnt from xparb;
 open crs1;
 loop
  fetch crs1 into v_seq1, v_seq2;
   if v_seq1 - v_seq2  1 then
    v_diff := (v_seq1-1)-v_seq2;
    for i in 1..v_diff loop
     dbms_output.put_line(v_seq2+i);
    end loop;
   end if;
  exit when crs1%notfound or crs1%rowcount &gt;= cnt;
 end loop;
 close crs1;
end;
-----------------------------------
and you&#039;ll end up with the result below:
1
3
7
-----------------------------------
Hope this is convenient enough.

Regards,
Mo’ Kassab</description>
		<content:encoded><![CDATA[<p>Dear Para,<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
I created a table named [xparb] containing 5 rows [2,4,5,6,8]. Run the code below:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
declare<br />
k   number(6) := 1; /* counter to count the number of unused serials [i just used k for Kassab] */<br />
cursor crs1 is<br />
 select seq,LAG(seq, 1, 0) OVER (ORDER BY seq) AS seq_prev<br />
 from   xparb; /* cursor to fetch all sequences in xparb table */<br />
cnt number; /* total count of sequences in our e.g. = 2,4,5,6,8 */<br />
v_seq1 number(5);<br />
v_seq2 number(5);<br />
v_diff number(5);<br />
begin<br />
 select count(*) into cnt from xparb;<br />
 open crs1;<br />
 loop<br />
  fetch crs1 into v_seq1, v_seq2;<br />
   if v_seq1 &#8211; v_seq2  1 then<br />
    v_diff := (v_seq1-1)-v_seq2;<br />
    for i in 1..v_diff loop<br />
     dbms_output.put_line(v_seq2+i);<br />
    end loop;<br />
   end if;<br />
  exit when crs1%notfound or crs1%rowcount &gt;= cnt;<br />
 end loop;<br />
 close crs1;<br />
end;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
and you&#8217;ll end up with the result below:<br />
1<br />
3<br />
7<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Hope this is convenient enough.</p>
<p>Regards,<br />
Mo’ Kassab</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Para</title>
		<link>http://www.xaprb.com/blog/2005/12/06/find-missing-numbers-in-a-sequence-with-sql/#comment-17795</link>
		<dc:creator>Para</dc:creator>
		<pubDate>Wed, 10 Feb 2010 21:51:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=57#comment-17795</guid>
		<description>Hello,

There is one question that no one has answered from my pont of view.
Given the series in a column 2, 4, 5, 6, 8
Return 1,3,7

Is there any query that can achieve this?

2 people asked this already but they didn&#039;t receive an answer.
Thanks in advance.</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>There is one question that no one has answered from my pont of view.<br />
Given the series in a column 2, 4, 5, 6, 8<br />
Return 1,3,7</p>
<p>Is there any query that can achieve this?</p>
<p>2 people asked this already but they didn&#8217;t receive an answer.<br />
Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohammed Kassab</title>
		<link>http://www.xaprb.com/blog/2005/12/06/find-missing-numbers-in-a-sequence-with-sql/#comment-17689</link>
		<dc:creator>Mohammed Kassab</dc:creator>
		<pubDate>Wed, 27 Jan 2010 07:31:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=57#comment-17689</guid>
		<description>To solve your problem we will assume that we have a table named “XPARB” composed of one column named “seq”, 
the table will accommodate the data u just provided. Kindly check the table description as shown …

desc test

desc xparb;
Name   Null  Type                                                                                                                                                                                          
-----  ----  -----
SEQ          NUMBER(5)  

If we issue …
select * from XPARB;
We result with …

SEQ
—
1
2
3
4
6
7
8
9
10
15
16
17
18
19
20

The PL\SQL code to produce the desired output is shown below...

set serveroutput on
declare
k   number(6) := 1; -- counter to count the number of unused serials [i just used k for Kassab]
cursor crs1 is
 select seq,LAG(seq, 1, 0) OVER (ORDER BY seq) AS seq_prev
 from   xparb; -- cursor to fetch all sequences in xparb table
cnt number; -- total count of sequences in our e.g. (15) = 1,2,3,4,6,7,8,9,10,15,16,17,18,19,20
v_seq1 number(5);
v_seq2 number(5);
v_diff number(5);
begin
 select count(*) into cnt from xparb;
 open crs1;
 loop
  fetch crs1 into v_seq1, v_seq2;
   if v_seq1 - v_seq2  1 then
    --dbms_output.put_line(v_seq1-1&#124;&#124;&#039;,&#039;&#124;&#124; v_seq2);
    v_diff := (v_seq1-1)-v_seq2;
    --dbms_output.put_line(v_diff);
    for i in 1..v_diff loop
     dbms_output.put_line(v_seq2+i);
    end loop;
   end if;
  exit when crs1%notfound or crs1%rowcount &gt;= cnt;
 end loop;
 close crs1;
end;

Hope that helps.

Regards,
Mo&#039; Kassab</description>
		<content:encoded><![CDATA[<p>To solve your problem we will assume that we have a table named “XPARB” composed of one column named “seq”,<br />
the table will accommodate the data u just provided. Kindly check the table description as shown …</p>
<p>desc test</p>
<p>desc xparb;<br />
Name   Null  Type<br />
&#8212;&#8211;  &#8212;-  &#8212;&#8211;<br />
SEQ          NUMBER(5)  </p>
<p>If we issue …<br />
select * from XPARB;<br />
We result with …</p>
<p>SEQ<br />
—<br />
1<br />
2<br />
3<br />
4<br />
6<br />
7<br />
8<br />
9<br />
10<br />
15<br />
16<br />
17<br />
18<br />
19<br />
20</p>
<p>The PL\SQL code to produce the desired output is shown below&#8230;</p>
<p>set serveroutput on<br />
declare<br />
k   number(6) := 1; &#8212; counter to count the number of unused serials [i just used k for Kassab]<br />
cursor crs1 is<br />
 select seq,LAG(seq, 1, 0) OVER (ORDER BY seq) AS seq_prev<br />
 from   xparb; &#8212; cursor to fetch all sequences in xparb table<br />
cnt number; &#8212; total count of sequences in our e.g. (15) = 1,2,3,4,6,7,8,9,10,15,16,17,18,19,20<br />
v_seq1 number(5);<br />
v_seq2 number(5);<br />
v_diff number(5);<br />
begin<br />
 select count(*) into cnt from xparb;<br />
 open crs1;<br />
 loop<br />
  fetch crs1 into v_seq1, v_seq2;<br />
   if v_seq1 &#8211; v_seq2  1 then<br />
    &#8211;dbms_output.put_line(v_seq1-1||&#8217;,'|| v_seq2);<br />
    v_diff := (v_seq1-1)-v_seq2;<br />
    &#8211;dbms_output.put_line(v_diff);<br />
    for i in 1..v_diff loop<br />
     dbms_output.put_line(v_seq2+i);<br />
    end loop;<br />
   end if;<br />
  exit when crs1%notfound or crs1%rowcount &gt;= cnt;<br />
 end loop;<br />
 close crs1;<br />
end;</p>
<p>Hope that helps.</p>
<p>Regards,<br />
Mo&#8217; Kassab</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amanda</title>
		<link>http://www.xaprb.com/blog/2005/12/06/find-missing-numbers-in-a-sequence-with-sql/#comment-17688</link>
		<dc:creator>Amanda</dc:creator>
		<pubDate>Wed, 27 Jan 2010 02:10:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=57#comment-17688</guid>
		<description>This article was incredibly helpful.  Thanks for posting it.</description>
		<content:encoded><![CDATA[<p>This article was incredibly helpful.  Thanks for posting it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manmohan</title>
		<link>http://www.xaprb.com/blog/2005/12/06/find-missing-numbers-in-a-sequence-with-sql/#comment-17472</link>
		<dc:creator>Manmohan</dc:creator>
		<pubDate>Wed, 23 Dec 2009 13:15:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=57#comment-17472</guid>
		<description>Hi,

How to find all missing sequencing no like 
your no is 
1,2,3,4,6,7,8,9,10,15,16,17,18,19,20

required output:
5, 11, 12, 13, 14

Thanks and regards;
Manmohan</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>How to find all missing sequencing no like<br />
your no is<br />
1,2,3,4,6,7,8,9,10,15,16,17,18,19,20</p>
<p>required output:<br />
5, 11, 12, 13, 14</p>
<p>Thanks and regards;<br />
Manmohan</p>
]]></content:encoded>
	</item>
</channel>
</rss>
