Generate a unique sequence number
HelloI need generate a unique sequence number. I use Oracle 11.2, here are the details. The idSeq column is specific idType a unique interior. I don't want a sequence for each idType.
create table tb_test (idSeq number (5), number (5) idType, addr varchar2 (256));
insert into tb_test
(to select when idSeq is null then 1 another max (idSeq) + 1 end, 3, "Main street");
I have an ORA-00937: not a single-group function error, any suggestion?
Published by: 939569 on February 13, 2013 11:21
Hello
939569 wrote:
HelloI need generate a unique sequence number.
Explain what you're trying to do, and why won't a sequence.
I use Oracle 11.2, here are the details. The idSeq column is specific idType a unique interior. I don't want a sequence for each idType.
create table tb_test (idSeq number (5), number (5) idType, addr varchar2 (256));
insert into tb_test
(to select when idSeq is null then 1 another max (idSeq) + 1 end, 3, "Main street");I have an ORA-00937: not an error of a single group group function,
Right. Given that the subquery uses an aggregate function (MAX), all in the SELECT clause must be an aggregate, a group of expression, a constant, or something that is entirely up to them. In this example, the CASE expression depends on idSeq, which is not an aggregate, not a group by expression (there is no GROUP BY clause) and not a constant.
In addition, the subquery must have a FROM clause. All queries and subqueries in Oracle require a FROM clause.
any suggestion?
Use a sequence. The numbers are not consecutive in each idType, but matter? Chances are, no matter what you do, you will not be able to maintain consecutive numbers within each idType anyway.
If you do not use a sequence, then you can try:
INSERT INTO tb_test (idSeq, idType, addr)
SELECT 1 + NVL ( MAX (id_seq)
, 0
)
, 3
, 'Main street;
FROM tb_test
WHERE idType = 3
;
Tags: Database
Similar Questions
-
Need to generate unique sequence number based on category
Hello
I have to update the NEW_NUMBER column with a unique number, taking into account the category column.
Here is the table structure and data.
{code}
create table (sample)
CATEGORY VARCHAR2 (100),
NUMBER VARCHAR2 (100),
NEW_NUMBER VARCHAR2 (100))
{code}
{code}
insert into sample values ("CAPACITOR ', ' 36858'," ");
insert into sample values ("CAPACITOR ', ' 37858'," ");
insert into sample values ("CAPACITOR ', ' 36958'," ");
Insert the sample values ('RÉSISTANCE', '46858', ");
Insert the sample values ('RÉSISTANCE', '47858', ");
Insert the sample values ('RÉSISTANCE', '46958', ");
{code}
I have to update the NEW_NUMBER column with a unique number, taking into account the category column.
Output would be like that.
{code}
Insert in the values('CAPACITOR','36858','270-01-0000001') sample.
Insert in the values('CAPACITOR','37858','270-01-0000002') sample.
Insert in the values('CAPACITOR','36958','270-01-0000003') sample.
Insert in the values('RESISTOR','46858','370-01-0000001') sample.
Insert in the values('RESISTOR','47858','370-01-0000002') sample.
Insert in the values('RESISTOR','46958','370-01-0000003') sample.
{code}
If you can help generate for one category, I'll do it for the other categories.
Thanks in advance.
Thank you
LAK
Not sure how you came up with 270 and 370. But with the information that you never provided that that's what I came with.
SQL > select * sample;
CATEGORY OLD_NUMBER NEW_NUMBER
---------- -------------------- --------------------
CAPACITOR 36858
CAPACITOR 37858
CAPACITOR 36958
RESISTANCE 46858
RESISTANCE 47858
RESISTANCE OF 469586 selected lines.
SQL > fusion in a sample
2 using the)
3. Select category
4, old_number
5, decode (category, "CAPACITOR ', ' 270', 'RÉSISTANCE', '370'")
6 || ' '-01 -.
7 || LPAD
8 (
9 row_number() over (partition by order of category by old_number)
10 , 7
11 , '0'
(12) new_number
13 for example
(14) b
15 on)
a.category 16 = b.category and
17 a.old_number = b.old_number
18 )
19 when matched then
20 update set a.new_number = b.new_number;6 lines merged.
SQL > select * from sample by category, old_number;
CATEGORY OLD_NUMBER NEW_NUMBER
---------- -------------------- --------------------
CAPACITOR 36858 270-01-0000001
CAPACITOR 36958 270-01-0000002
CAPACITOR 37858 270-01-0000003
RESISTANCE 46858 370-01-0000001
RESISTANCE 46958 370-01-0000002
RESISTANCE 47858 370-01-00000036 selected lines.
-
The incorporation of a sequence number (function?) Within Adobe Document?
Hello, alumnus of Adobe:
I just received my Application SR investigated. Director via the IOC of our University reclassification option to the next task:
Question: Is it possible to incorporate a unique sequence number within each download of an Adobe form, which of course can be filled with data from the Office users (which is a common thing today). The question is really which option are available (i.e., Action Script, Javascript, IE) within Adobe to create a function of the sequence, or we look at using technolgy server for everything that is hosting our Adobe software infrastructure side (Coldfusion, Dreamweaver, i.e.)?
Thank you.
Preston Thornton
Software integrator SR.
There are many techniques that can be subscribed form used global variables, a field day or SQL database to track the sequence number, but the exact method will be your choice.
See basis (Open Document) Document level Scripts for the increment field, but we should save the form before the next person opens the form.
See Journal August 2004 Acumen for the use of the variable global counter.
-
generate a different sequence for 32 different warehouse...!
We have around 32 different warehouse where the materials are stored...
I need to design a form that I generates a different sequence number for the materials stored in 32 different articles home
ex
can someone help me with this :)name:suhail pwd:123 warehouse: America Now after i login i want to generate a sequene number only for america's ware house say 21001 name:ANDREAS pwd:345 warehouse:France for this user the sequence number generted should be different say some thing like 31001
Published by: Chase Suhail on October 2, 2010 22:37I still prefer to use a "real" sequence Lets assume that your seuqneces are appointed as SEQUENCE_
. Create a stored procedure in the database, as
FUNCTION FK_SEQUENCE_FOR_WAREHOUSE(i_vcWarehouseCode IN VARCHAR2) RETURN NUMBER IS nId NUMBER; BEGIN EXECUTE IMMEDIATE 'SELECT SEQUENCE_'||i_vcWarehouseCode||'.NEXTVAL FROM DUAL' INTO nId; RETURN nId; END;
-
need to generate unique sequence for each transaction number
need to generate unique sequence for each transaction numberUse sometihng like that
use the orcl: sequence-next function val
-
create table t (id int primary key, dt date, file_no int, batch_no int, data varchar2(5) ); insert into t values (1,trunc(sysdate),23,113,dbms_random.string('a',5)); -- 1.1.1 insert into t values (2,trunc(sysdate),23,345,dbms_random.string('a',5)); -- 1.2.1 insert into t values (3,trunc(sysdate),23,345,dbms_random.string('a',5)); -- 1.2.2 insert into t values (4,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.1 insert into t values (5,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.2 insert into t values (6,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.3 -- insert into t values (7,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.1 insert into t values (8,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.2 insert into t values (9,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.3 insert into t values (10,trunc(sysdate),24,222,dbms_random.string('a',5)); -- 2.2.1 insert into t values (11,trunc(sysdate),24,222,dbms_random.string('a',5)); -- 2.2.2 insert into t values (12,trunc(sysdate),24,111,dbms_random.string('a',5)); -- 2.3.1
Oracle 11.1
How can given this structure and data, I generate sequence at the end of each line numbers? Basically, the sequence number (x.y.z) is such that x (1.n) is awarded for each unique value in file_no. In each x, y (1.n) is assigned for each unique value of batch_no. Within each y, z (1.n) is assigned for all records of this batch. Sample data shows only dt but all sequences must reset and start over when dt changes.
I tried using row_number() over (partition by dt, file_no) and such but nothing quite gives me what I'm looking for.
Help? Thank you
Hello
HELEN wrote:
If you look at my CREATE TABLE, the ID column is a primary key and represents the order of the data in the file.
Done batch_no = 100 come before or after 101? Batch_no = 100 a ID so much until after the id for batch_no = 101.
Good point, but that won't happen because of the way the 'record' is generated. All batch_nos will be contiguous. So if batch_no 100 comes earlier in the file as 101, it should get some 2nd highest sequence number. Otherwise, lower. Basically, the 2nd part of the sequence must simialar logical number to the 3rd party (i.e. order by id) but that messes things. Still struggle with it. Any help appreciated.
I think I understand. You say that, because of the way that the ID is issued, it wouldn't matter if you used the highest id of the batch_no, or the lowest id, or the average, or if you chose one at random; you would get the correct order in all cases.
The following query uses the id low in the order file_no and batch_nos.
WITH got_min_ids AS
(
SELECT id, dt, file_no, batch_no, data
MIN (id) over (PARTITION BY dt
file_no
) AS min_id_file_no
MIN (id) over (PARTITION BY dt
file_no
batch_no
) AS min_id_batch_no
T
)
SELECT id, dt, file_no, batch_no, data
DENSE_RANK () OVER (PARTITION BY dt
ORDER BY min_id_file_no
)
|| '.'
|| DENSE_RANK () OVER (PARTITION BY dt
file_no
ORDER BY min_id_batch_no
)
|| '.'
|| ROW_NUMBER () OVER (PARTITION BY dt
file_no
batch_no
ORDER BY id
) AS seq
OF got_min_ids
ORDER BY dt, min_id_file_no, min_id_batch_no, id
;
The main request is in fact what I posted before, but instead of
"ORDER BY file_no" and "ORDER BY batch_no", she uses
"ORDER BY min_id_file_no" and "ORDER BY min_id_batch_no". These values are calculated in the subquery, got_min_ids.
Output (including the additional sample data I posted):
ID FILE_NO DT BATCH_NO SEQ DATA
---------- ----------- ---------- ---------- ----- ----------
1 23 25 April 2014 113 dXAad 1.1.1
2 345 23 25 April 2014 pumVG 1.2.1
3 345 23 25 April 2014 jLnbO 1.2.2
4 23 25 April 2014 543 xKhCL 1.3.1
5 23 25 April 2014 543 JQoWk 1.3.2
6 23 25 April 2014 543 YjJeC 1.3.3
7 24 25 April 2014 333 WjQNE 2.1.1
8 24 25 April 2014 333 ScWSL 2.1.2
9 24 25 April 2014 333 pXDSD 2.1.3
10 222 24 25 April 2014 OSajn 2.2.1
11 222 24 25 April 2014 QNpix 2.2.2
12 24 111 OwkjI 2.3.1 April 25, 2014
91 100 99 25 April 2014 sRWmT 3.1.1
93 100 99 25 April 2014 IAEFd 3.1.2
92 101 99 25 April odQxh 2014 3.2.1
I know you said that this situation is impossible (that is, if ID 91 and 93 have the same batch_no, then id 92 cannot have a different batch_no), but the application works even if this rule is broken.
-
Insert/update of the XML help merge and to generate the sequence number
Hello
I'm working on Oracle 11 g.
I have a doubt with loading XML.
I get an xml and I need to insert or update data in a table. What I can accomplish by using the MERGE statement.
But there is a column in A table, I need to fill with a sequence number, based on the data sent in the xml file.
The XML does not send the data in this column.
And I have to make sure that sequence is created according to the order in which the records are present in xml.
For example the MERGER is insert five rows and update two lines and insert again 3 rows of xml in table A. The sequence number must be created in the same order for the column in the table.
Also for every new XML, the sequence starts with 1 and ends with the number of records in the xml file. I can't create a sequence and use the seq.nextval.
Please let me know, there is a way to achieve this.
Thank you!
Published by: 934451 on 8 August 2012 06:33
Published by: 934451 on 8 August 2012 06:50Hello
As a result of your previous thread: {: identifier of the thread = 2403469}
You can use the clause for ORDINALITE in XMLTable to generate the necessary sequence:
MERGE INTO target_table t USING ( SELECT x.seq_num, x.pk_id, x.col1, x.col2, ... FROM XMLTable( '/root/record' passing my_xml_doc columns seq_num FOR ORDINALITY , pk_id number path 'ID' , col1 varchar2(30) path 'COL1' , col2 varchar2(30) path 'COL2' , ... ) x ) src ON ( t.pk_id = src.pk_id ) WHEN MATCHED THEN UPDATE SET t.seq_num = src.seq_num , t.col1 = src.col1 , t.col2 = src.col2 , ... WHEN NOT MATCHED THEN INSERT (seq_num, pk_id, col1, col2, ...) VALUES (src.seq_num, src.pk_id, src.col1, src.col2, ...) ;
-
is there any function in the osb to generate a unique number in proxy
is there any function in the osb to generate a unique number in proxyFN - bea: uuid()
The function fn - bea: uuid() returns a universal unique identifier. The function has the following signature:
FN - bea: uuid() as XS: String
You can use this function in the pipeline of proxy to generate a unique identifier. You can insert the unique identifier that is generated in an XML document in the form of element. You are unable to generate a unique identifier to the system variable. You can use this to edit a message payload.
For example, suppose you want to generate a unique identifier to add it to a message for follow-up purposes. You can use this function to generate a unique identifier. The function returns a string that you can add it to the SOAP header.
-
Generating unique random number with a Boolean signal on an RT target
Hello, this is my first time asking your question. I apologize if I post this question in the wrong Council.
[What I'm trying to do]
I am stable heating and cooling in an experimental space that I (with cRio9024).
And I'm putting a different experimental condition in space based on the function 'random number '.
'Different experimental conditions' sense different combinations of Tind, Twat_s and mdot (refer to the attached VI).
For example, if I get the Boolean TRUE signal.
I should have a set of [Tind, Twat_s, mdot] = [21,14,0.05], and IS this set of numbers until this Boolean signal goes to FALSE.
And when the signal passes to the TRUE once again.
I should have a different set of [Tind, Twat_s, mdot] = [24,16,0.15] for example.
[I]
Problem I am with my code is that,
When the VI is running, the random number remains the same as the Boolean signal is set to TRUE.
From what I tried so far for the last couple days, using 'the event structure' was the message more concerned that I found,
However, LabView help tells me that "structure of the event" on the objectives of the RT do not support the events associated with the user interface such as the façade of VI or controls panels.
I would therefore ask a quick help, since my knowledge of LabView is exhausted at this point.
This is so the part where I want to generate random numbers, WHEN this structure case is TRUE.
convert whole numbers, random numbers
Use them as a table index,
while I can choose conditions from radom to the given set of conditions.
Once more, I want to do is,
generate a SINGLE random number series when the structure above is TRUE.
Hope I have developed quite clear.
I'm appreciated for any kind of advice.
Thank you!
You just need to store the Boolean from the previous run. Then the logic would be (I'll call her Boolean previous B_prevand current boolean B):
If B AND B_prev > don't generate new values
otherwise if B > generate new values
Edit: to store your Boolean value, you can use a feedback node, or a loop with N = 1 and a registry change.
-
Sequence number to generate an item Code
Dear friend
I want to change my existing master finished painting and want to give a fresh article number in the following way.
ITEM_TYPE ID
----------- --------------------
RAW 100000001
CYLINDER 200000001
300000001 ENGINEERING
VARIOUS 400000001
500000001 PRODUCTS FINISHES
Can you suggest me which application I should give. While in short time I can update my itemmaster with new item code table.
SandyFirst Exchange with the item_type, then a numeric sequence number?
declare cursor types is select distinct item_type, rownum n from items ; begin for r in c loop update items set id = r.n||to_char(rownum,'FM00000000') where item_type=r.item_type; end loop; end; /
Max
[My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/] -
Synthetic Primary Key (sequence number) vs natural primary key
I wonder if the sequence number is better than the primary key. I found a few tables only use the sequence number, some tables use the primary key only, and a few tables use both. Can someone give me a clue, one that I use when you create a table? TX in advance.
Published by: 1B, 3 may 2012 21:07I'm not sure I understand the question. I do not understand how it is either / or question.
Virtually every table must have a primary key. You can either use a primary key natural (something in the data that is unique and immutable) or you would use a synthetic primary key which is filled from a sequence. I strongly suggest using synthetic primary keys generated from a sequence for your primary key.
Justin
-
Min and Max of the sequence number
Hello
I have a table called pins (lot number 4,
Sequence number (8)
);
I have data in the table:
batch sequence
386 100
386 101
386 102
386 800
386 801
1 387
2 387
I want to know by draw the low values and high for sequence number, is the result, I am looking
batch min (sequence), max (sequence)
386 100 102
386 800 801
387 1 2
Oracle 10g rel2
Thank youHello
You want something like this:
WITH got_grp AS ( SELECT lot , seq_num -- SEQUENCE is not a good column name , seq_num - ROW_NUMBER () OVER ( PARTITION BY lot ORDER BY seq_num ) AS grp FROM pins -- WHERE ... -- any filtering goes here ) SELECT lot , MIN (seq_num) AS min_seq_num , MAX (seq_num) AS max_seq_num FROM got_grp GROUP BY lot , grp ORDER BY lot , min_seq_num ;
If I understand the probem, you want to GROUP BY, but many does not define groups by itself: each contiguous set of seq_nums in a batch is a separate group. In each of these groups, the difference between seq_num and a meter which reflects the order of seq_num generated in the query (using ROW_NUMBER) will be constant.
This assumes that seq_num is an integer, and this (lot, seq_num) is unique.
If this is not the case, the above query will have a small adjustment.If you want to display the INSERT statements for your sample data, then I could test this.
-
Generate a binary sequence with the NI USB-6008
Hi all
I'm new to LabView and I am trying to generate a binary sequence with a box NI USB-6008. The sequence, I'm currently generate is a counter of 5 bits, i.e. 00000 00001 00010, 00011... 11110, 11111 placing each bit in a different digital IO of the of the 6008 NOR, so that I can use the County as the bits of selection in a decoder/demux.
I managed to simulate the binary sequence and produce a graphical interface, but I have not found how to generate the sequence of bits with the NI 6008.
Totally, I'd appreciate any help you could provide. Thank you very much.
Hi JosephM,
Good Afternooon and I hope your well today.
I just tested the code on a 6008 and also released the above code is very complex - I was for some reason any fixed on using Boolean tables.
Please see the attached code, in LabVIEW 8.6.
Mind you, I have configured the task as a channel for all lines. i.e. digital single I spent, is the task value should apply to all channels selected in the entry. So if you select only port0/Dev8/$line0 for example, the DAQmx driver will examine the LSB of the digital and work so $line0 must be true from the false. It will NOT update all other channels. So when I select line0:4 - it will update the first 5 lines (bits) in digital. As the code generates a number from 0-32 he emotional generates 00000 to 11111.
I hope this finds you well and sorry for the first post!
-
Hi all.
I really need your help on this:
(1) version: 11.2.0.1 EE / Windows.
(2) database does not start, don't get database.
Alert.log info:
Instance of stopped by USER, pid = 3652
2015-11-22 15:57:19.763000 - 04:30
I found this after using adrci:
2015-11-22 15:49:15.727
SESSION ID: (191.1) 2015-11-22 15:49:15.727
CUSTOMER ID :() 2015-11-22 15:49:15.727
NAME OF THE SERVICE :() 2015-11-22 15:49:15.727
MODULE NAME: (sqlplus.exe) 2015-11-22 15:49:15.727
ACTION NAME :() 2015-11-22 15:49:15.727
Informational message:
Control file 1 has seq 2713995, low 2713994 file # 0
Error: kccpb_sanity_check_2
Control file sequence number mismatch!
fhcsq: bhcsq 2713995: 2714016 cfn 0
2015-11-22 15:49:15.758
USER (ospid: 2504): put an end to the instance
Verification of MOS Note: 435436.1 I must:
(1) to restore a backup of a controlfile and recover
OR
(2) to recreate the controlfile
OR
(3) restore the backup data and recovery
It is a database, that I was not, up to now administer. But:
(1) I tried from the database with addressed controlfile (the one located in FRA). No luck. (Create pfile from spfile / startup pfile)
(2) the database is not mount / open. It hangs on the editing process. So I can not issue an alter database controlfile to trace.
It seems that my options are:
(1) manual creation of controlfile with open resetlogs option. This option is viable, but risky if we miss a datafile or something GOLD
(2) restoration of RMAN backup. The thing is that the most recent copy of automatic backup of controlfile is since a few days early (4 / 5 days).
I found this link: http://gavinsoorma.com/2009/07/rman-recovery-from-loss-of-all-control-files/
The procedure seems easy, but since this controlfile is not in the current SNA of database (data files, etc.). I'm not sure it if it would work.
So in short, I think I have an automatic backup controlfile and it's OK. but a little old. I can restore from this copy of CF?
Please I'm pressed real here, so help will be greatly appreciated!....
Thanks in advance!
Best regards, Luis...!
Hello
It seems that my options are:
(1) manual creation of controlfile with open resetlogs option. This option is viable, but risky if we miss a datafile or something GOLD
(2) restoration of RMAN backup. The thing is that the most recent copy of automatic backup of controlfile is since a few days early (4 / 5 days).
It seems that you have few options,
In my opinion, you should start with option 2), but you have logs archived redo and all and all the backups of catalog and perform a restore.
After, if not works, you must manually create the control files, but you are right, you must carefully on all the data files. Here a log generated in the last level 0 RMAN backup could help you, don't forget the newspaper are all entries of data for backup files.
I wish to have more ideas to help you, but I have no other.
I hope this helps.
Kind regards
Juan M
-
How generations for db in the XSLT file sequence number
Hello gurus SOA,.
I have a requirement, please see below
I am using SOA 11.1.1.6
Insert a webservice to db, XSLT call, I have 10 items next to the source and 11 items next to the target.
- Source to target first 10 mappings are performed.
- Now the requirement is, for the 11th element target we must pass a sequence number to the database targeted, means-(sequence number must be generated for each execution of the XSLT execution)
How do the last point?
Can someone help me please
Hello
You can pass the sequence number in the 11th element to help. "
oraext:sequence-next-val("Sequence name as a string", "Datasource as a string") function.
Kind regards
Anshul
Maybe you are looking for
-
Unable to get the song on ipod
I opened it in iTunes and got 51 Wav songs on it but it wouldn't hold any more. I then went online looking at a manual, and I realized I needed to convert songs to a lower compression. I formatted the iPod and then tried to compress some songs, but I
-
I have a question why U removed the session of keyboard spelling checker is a very useful sit Apple give it in products. It helps a lot in communicting with others from different countries, even in our studies and communication with our teachers.plz
-
When I select emails I want to remove the delete button and all the other buttons in the same row do not work. This not only with hotmail, it seems to be with other applications, including on this page at the top where you have "Home, office, int exp
-
Google now does not work after update of KitKat 4.4.4
After update of KitKat 4.4.4 now Google no longer meets the key word 'OK Google'. Before you update it never failed to respond to the key word.
-
Help! my screen is upside... allows you to type this a challenge!
my young grandson tapped a few keys and microsoft turned upside down! When turn on the opening screen is ok but when Google opens it is turned round. !! Any help appreciated people...