Finding ranges in a resetting sequence number column
Hi,
I'm trying to run a query to get daily transactions on an ATM machine
The record on the ATM Machine is as such
TRANSACTION DETAILS TRANSACTION DATE TRANSACTION_SEQUENCE
..............xyz............... MON-DD-YYYY 1 to 9999
now after each 9999 transactions the number sequence resets and from there on it is 1, 2, 3, 4 and so on.
Now I'm going to accept the ranges as:
From Date, From SEQ No
To Date, To Seq No
Then I'm searching as
DATE Between FR_DT and TO_DT
and (
(DATE = FR_DT >= FR_SEQ) and
(DATE = TO_DT <= TO_SEQ)
Problem emerges when the SEQ number resets. For Example I may have the TO_SEQ given as 1, but the previous sequence is 9999.
Let me know if I can explain something else as well.
I need your help
Maybe this could help you
where ( FR_SEQ < TO_SEQ
AND TRANSACTION_SEQUENCE between FR_SEQ and TO_SEQ
or ( FR_SEQ > TO_SEQ
AND (
TRANSACTION_SEQUENCE between FR_SEQ and 9999
OR TRANSACTION_SEQUENCE between 0 and TO_SEQ
)The first part will check when the TRANSACTION_SEQUENCE is falling between FR_SEQ and TO_SEQ
The second part will check when TO_SEQ have spanned over 9999
Alon
Similar Messages
-
Need SQL statement to generate a sequence number in the output rows
Hi folks. I need to create an SQL statement that generates a sequence number column in the output rows (records) such that the first returned row has this column set to 1, second returned row has the column set to 2, etc.
For example, consider the query:
SELECT income from employees WHERE income != 20000 ORDER BY income;
If employees.income contains 60,000, 20,000, 35,000, and 19,000 for respective rows, the output would be this:
19,000
35,000
60,000
I would like the SQL to also return a sequence number that is computed across the returned rows, resulting in two output columns:
1 19,000
2 35,000
3 60,000
Is there a simple SQL function that generates the sequence number, in order, and only for the returned rows? Or is there another way?
I'm stumped. Any help is appreciated! Thanks!
- Jack CochraneHi,
Welcome to the forum!
Use ROWNUM, like (example):
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> select rownum, first_name from (select e.first_name from employees e where e.first_name like 'J%' order by e.first_name);
ROWNUM FIRST_NAME
1 Jack
2 James
3 James
4 Janette
5 Jason
6 Jean
7 Jennifer
8 Jennifer
9 John
10 John
11 John
12 Jonathon
13 Jose Manuel
14 Joshua
15 Julia
16 Julia
16 rows selected
SQL> But rememeber if you want to be sure of unique numbers in certain field is better to use sequences and use seq_name.nextval each time you need.
Regards, -
FInding missing sequence number
Dear All
I have a column in table like this (actually its just a sample):
TAB
MMxxxx9988
MMxxxx9990
MMxxxx9995
MMxxxx9998
MMxxxx9999
MMxxxx0000
MMxxxx0001
MMxxxx0003
MMxxxx0004
MMxxxx0005
MMxxxx0008
xxxx is variable
last four digit is a sequence number start with 0000 and end with 9999.
when the last four digit exceeds 9999 it reset to 0000
My question is : how can we find the missing sequence number for that column.
example:
for the above table , it should give the below result:
TAB
MMxxxx9989
MMxxxx9991
MMxxxx9992
MMxxxx9993
MMxxxx9994
MMxxxx9996
MMxxxx9997
MMxxxx0002
MMxxxx0006
MMxxxx0007
ThanksOne another way of doing it:
For ease of verification, I have removed the records from 0001 to 9988.
with data as
select 'MMxxxx9988' col from dual union all
select 'MMxxxx9990' col from dual union all
select 'MMxxxx9995' col from dual union all
select 'MMxxxx9998' col from dual union all
select 'MMxxxx9999' col from dual
-- select 'MMxxxx0000' col from dual union all
-- select 'MMxxxx0001' col from dual union all
-- select 'MMxxxx0003' col from dual union all
-- select 'MMxxxx0004' col from dual union all
-- select 'MMxxxx0005' col from dual union all
-- select 'MMxxxx0008' col from dual
select distinct col, nxt_val, substr(col, 1, 6) || to_char(st_with + level, 'fm00009') miss_seq
from (
select col, nxt_val, col_num st_with, nxt_col_num end_with
from (
select col, lead(col) over (partition by substr(col, 1, 6) order by substr(col, -4, 4)) nxt_val,
to_number(substr(col, 7, 4)) col_num, to_number(substr(lead(col) over (partition by substr(col, 1, 6) order by substr(col, -4, 4)), 7, 4)) nxt_col_num
from data
where abs(col_num - nxt_col_num) > 1
connect by level <= (end_with - st_with) - 1
and prior col = col
and prior sys_guid() is not null
order by col;
COL NXT_VAL MISS_SEQ
MMxxxx9988 MMxxxx9990 MMxxxx09989
MMxxxx9990 MMxxxx9995 MMxxxx09991
MMxxxx9990 MMxxxx9995 MMxxxx09992
MMxxxx9990 MMxxxx9995 MMxxxx09993
MMxxxx9990 MMxxxx9995 MMxxxx09994
MMxxxx9995 MMxxxx9998 MMxxxx09996
MMxxxx9995 MMxxxx9998 MMxxxx09997
7 rows selected -
Sequence number for group of values in column
I need to create a sequnece number in a column starting from 5 and incremented by 5, based on values presenet in first column. If the value in first column changes then the sequence should start again with 5 and increment by 5.
for example: I want to generate the following output
Cat_code Seq_No
1001 5
1001 10
1001 15
1001 20
2001 5
2001 10
2001 15
3001 5
3001 10
4001 5
4001 10
4001 15
4001 20
5001 5
6001 5
7001 5
7001 10
7001 15
7001 20
7001 25
So if the cat_code changes, the sequence number should again start from 5 and should be generate sequence number until the cat_code changes again.
any help apreciated.
Thanks
RahulHi, Rahul,
You can use the analytic ROW_NUMEBR function to generate the numbers, like this:
SELECT cat_code
, 5 * ROW_NUMBER () OVER ( PARTITION BY cat_code
ORDER BY NULL
) AS seq_no
FROM table_x
ORDER BY cat_code
, seq_no
;You must use an analytic ORDER BY clause when you call ROW_NUMBER. If you don't really care about the order, then you can ORDER BY a constant, but you still need the analytic ORDER BY clause. -
Sequence number adjustment in the column
In my table maintenance generator,
I have one field called sequence number which increments by '1', each time user enters a new record in my table maintenance generator(have coded in such a way).
now the internal table, under sequence column if some records get deleted,
then the numbering of that column should be adjusted automatically.
Like
1st record - 1 A B D
2nd record - 2 A B C
3rd record - 3 A B D
4th record - 4 A B C
5th record - 5 E D F
If some user deletes 3rd record , then instead of showing the TMG as below
1st record - 1 A B D
2nd record - 2 A B C
3th record - 4 A B C
4th record - 5 E D F
the TMG should should show as
(I need that to be sequence column adjusted as )
1st record - 1 A B D
2nd record - 2 A B C
3th record - 3 A B C
4th record - 4 E D F
My thought is to write on new module in PAI,
and buils the logic in case of syst-ucomm = 'DELE'.
Please suggest me any function module availble or any good logic for this
Thanks in ADV.This really isn't the way the TMG was meant to be used. Normally, one just uses it to manually add change or remove individual records, not a number of records based on some logic. It would probably be simpler to build a simple dynpro to take care of this.
Rob -
Automatic resetting of Number Range
Hi,
I have Created a number range, i want to reset that at the end of the financial year. Can anybody tell me how to do that.
Regards.
BaijuYou need to go to transaction SNRO. You need to know the for which object you rae creating the number range. After this, when you want to reset the number range for next financial year say, 2007-2008, you should put a new entry for the year 2007 and assign the from and to range for this year.
Lakshminarayanan
Mark and reward points for all good answers. -
In standby db, can't find sequence number of Last Applied Log.
Hello,
Standby database is behind the primary database for over 200 hours, to repaire this, we are using a incremental backup from primary database and a restored control file.
after starting up standby database, in Grid Control (OEM), can't find "last applied log" sequence number,
go to that standby, do
standby> select max(sequence#) from v$archived_log where applied='YES';
MAX(SEQUENCE#)
go to primary,
do
SQL> select max(sequence#) from v$archived_log where applied='YES';
MAX(SEQUENCE#)
83833
then using OEM grid control, to Verify checks various standby database settings.
Initializing
Connected to instance standby_server:standby
Starting alert log monitor...
Updating Data Guard link on database homepage...
Skipping verification of fast-start failover static services check.
Data Protection Settings:
Protection mode : Maximum Performance
Redo Transport Mode settings:
primary.com: ASYNC
standby.com: ASYNC
Checking standby redo log files.....OK
Checking Data Guard status
primary.com : Normal
standby.com : Normal
Checking inconsistent properties
Checking agent status
Checking applied log on standby........WARNING:
Timed out after 60 seconds waiting for log to be applied.
Processing completed.
so how to fix this?
thanks you very much.
Edited by: 951932 on Oct 18, 2012 7:44 AMHello;
Probably nothing to fix. This is a common warning message.
It even occurs in this example :
http://www.databasejournal.com/features/oracle/article.php/10893_3826706_2/Oracle-11g-Data-Guard-Grid-Control-Management.htm
Best Regards
mseberg -
How can find SCN or sequence number on the update operation?
nedd to recovery database, how can find the SCN or sequence number before the update exection?
thanksnedd to recovery database, how can find the SCN or
sequence number before the update exection?Sorry - there is something confusing about your question ...
It seems to me the SCN is the 'system change number', which identifies when a change (table, row, block, flush log buffer to log file, etc) has ocurred.
You seem to be asking for the SCN associated with an update before the update actually occurred.
Are you actually asking "How do I perform a point in time recovery to immediately before a specific update?"
Perhaps you could include a few more details, such as database version. For some reason different versions have different capabilities - that could be helpful here. -
Significance Sequence Number in PO delivery confiramtions
significance Sequence Number in PO delivery confiramtions.
I know its the sequence in which vendor confirms his goods to be delivered.
But, I want to know how the number gets generated. If i go to EKES table for 1 perticular PO with delivery confirmations.
I am not able to find the "Sequence number" in series. Number will be jumbled.. its ok...but say number 3 will be missing out of series.
Refer to last column in below table for Sequence number.
CC DDelivery DTimeQuantiReference Created onInb. DelItmHL IteBatch Quantity RedM MPN Materl C Seq. Number
ZH D11.03.2010 1,00 7008557420 14.12.2009 0 0 0,00 1 2
AB D11.03.2010 1,00 7008557420 18.12.2009 0 0 0,00 3 6
ZH D11.03.2010 1,00 7008557420 18.12.2009 0 0 0,00 1 7
ZH D31.03.2010 1,00 7008557420 18.12.2009 0 0 0,00 1 4Hi ,
Could be some of the confirmations have been deleted -
Portal Master-detail form how to auto assign detail record sequence number
Portal Master-detail form how to auto assign detail record sequence number.Please help me?
You can just read the following section
Can I specify a sequence number generator as the default value for a form column?
Yes. Enter the following in the "default value" field for the column:
#<schema name>.<sequence name>.nextval
where <schema name> is the name of the schema containing the sequence, and <sequence name> is the name of the sequence. The entry is preceded by a "#".
For example, if the schema name is "SCOTT", and the sequence name is "CUSTOMER_SEQ", the default value entry is:
#SCOTT.CUSTOMER_SEQ.NEXTVAL
same way you can do for master - detail form.
for more information on forms please refer the following URL.
http://otn.oracle.com/products/iportal/htdocs/portal_faq.htm#BuildingApplications
hope it helps. -
How can I reset the number authorized Macs in my account?
How can I reset the number authorized Macs in my account? Two old Macs that I no longer have are still authorized, which leaves me with three working macs at home.
Hello Joe
You will find your answer on this page. In summary you have to deauthorize each of the 2 Macs on the Mac thenself. If it's no longer possible, then you have to deauthorize all five Macs and then reauthorize each 3 remaining
http://support.apple.com/kb/HT1420
Bye -
File sequence number in a Flat file
Hi,
I am working on Idoc to file scenario wherein my output file will have a sequence number assigned to each level.
there are 4 levels and hence 4 sequence number to be genearted and its values should also have the same sequence number.
i am doing this just by using Counter function.
But when i am getting a multiple detail records, for each detail record(0040) level its keep incrementing.but it should have the same value what its level has.
for ex:
ALPHAMER AS2 E5 710 20114806124829 01.00
0000 00000000 20100102 V3.0 SORD CZ1
0010 00000001 76767 123 100 WER Constant BNG 560011 RAJ WERR 560011 BTM X EN RT
0020 00000001 TYUIOP
0040 00000001 8765 6532 200 45 10 WE 20 AG
0040 00000002 8765 6532 200 45 10 WE 20 AG
0040 00000003 8765 6532 200 45 10 WE 20 AG
0040 00000004 8765 6532 200 45 10 WE 20 AG
9999 99999999
It has to be like this.
ALPHAMER AS2 E5 710 20114806124829 01.00
0000 00000000 20100102 V3.0 SORD CZ1
0010 00000001 76767 123 100 WER Constant BNG 560011 RAJ WERR 560011 BTM X EN RT
0020 00000001 TYUIOP
0040 00000001 8765 6532 200 45 10 WE 20 AG
0040 00000001 8765 6532 200 45 10 WE 20 AG
0040 00000001 8765 6532 200 45 10 WE 20 AG
0040 00000001 8765 6532 200 45 10 WE 20 AG
9999 99999999
Can someone help me in achieving this.
RegardsHi there,
Just to try out from a different view, the following case could be implemented if the pre-requiisites are satisfied:
Pre-requisites:
1) The element that carries a primary factor, let us say, '8765' from your example.
2) Functionally there is an element in your header item that relates the line items under it.
My understanding of your example:
1) Line items present for 00, 10, 40
2) Line item 30 absent in the series
Proposal:
Map source field (the one that is arelating factor, here the one that carries '8765') -> INDEX (start by 0, increment by 1) -> multiply by one.
INDEX standard function property: Donot Reset for every context;
Srikanth Srinivasan
Edited by: Srikanth Srinivasan on Jan 10, 2011 11:02 AM -
Error While Generating Sequence Number. Contact your system Administrator
Hi All,
I have developed a form to provide our client with 'an easy to fill' User Interface. This form will be used instead of the standard form present in Business Suite.
Some columns of the table, on which form is based, are getting populated via generation of sequence numbers.
Now the problem is, after deploying custom form developed by me in the instance, Standard form is showing this error
" Error While Generating the Sequence Number. Please contact the System Administrator "
I am unable to trace why this error had started appearing..
Any suggestions would be of great help...
Thanks in Advance,..Forms version 6i,
Database version 9.2.0.6.0
Sequences which I am using are used there in Standard form also..
So evrytime i need to save the record, I am selecting NEXTVAL of it into
the respective item of the datablock.. -
How to find out the length of a LONG column?
How can I find out the length of a LONG column, I should write a stored procedure which will return me the length of a LONG column passed as an argument to it!
any ideas or suggestions? please respond, i need this urgently, or you can mail me at [email protected]
thanks,
sriniActually a LONG variable in PL/SQL maxes out at 32K, so this would not be accruate. If you are running Oracle 8+, you could do a conversion to LOB which will give you an accurate length. Note, this example needs a table created to hold the converted lob value, you can't do it directly in pl/sql:
create table lobhold
(templob clob);
declare
mylength number;
begin
execute immediate 'insert into lobhold select to_lob(text) from equipment_notes where equipment_id=1448';
select dbms_lob.getlength(templob) into mylength
from templob;
dbms_output.put_line(mylength);
execute immediate 'truncate table lobhold';
end; -
Sequence number in process order
Hi,
Kindly brief about usage of sequence number, which is in process order with example. Is this can be used for capacity leveling. If so how that can be done.
If one sequence number is assigned to multiple process orders means double entries, then what is the impact during capacity leveling based sequence number.
Is number range is maintained any where in SPRO for sequence number. If so where? Is there any possibility to maintain number range for sequence number if required?
Thanks & Regards,
N. Laxman1.Seq. number in an order
Number that can be assigned to production orders or planned orders at the level of the task list header and is therefore valid for all the operations in an order.
The sequence number is used to sort the orders for the display on the planning table and to
form a dispatching sequence using the sort key.
3.
Maybe you are looking for
-
Hi can someone please help, i ve got a new computer (windows7) and a new shuffle, and its asking to aurthrized the computer before i down load anything for i tunes that ihave already bought. but there is no explaination on how to do this any ideas
-
My Photo Stream not updating in new Photos app
I do NOT have iCloud photo library on, so why won't My Photo Stream update?
-
Problem with importing a clip from another iMovie project
Hello I want to import a clip from one iMovie project to another iMovie project. Both projects are in 16:9, but when I import a clip it's no longer in 16:9. The clip is croped and I have a black bar on the right and left side. How can I solve this ?
-
Hi, I have wrote a program using CL_GUI_ALV_TREE. I want to make some of the columns editable. Alternatively, is it possible to include a tree structure in normal CL_GUI_ALV_GRID? Thanks. Michael Pang
-
Iphoto won't display photos or run a slideshow - just a black screen. Can't see photos to edit etc. Thumbnails all OK and all else seems visible in the usual way etc. Tried rebuilding library and reset Mac Air but no result. Ideas please!!!!