Generate the sequence of random by number
How to generate random random 4 digit number using the sequence or any other method. Please suggestTake a look at http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_random.htm#ARPLS040
Concerning
Etbin
Tags: Database
Similar Questions
-
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.
-
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
-
Can any body help to get a script that can generate the sequence (length 3) with a combination of numbers and characters example: T11... TA1... TZ9... then on
With the help of the clause type
Select sqnc
from (select sqnc
from (select 'T00"sqnc, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ordr
of the double
)
model
size of (0 I)
measures (sqnc, ordr, length (ordr) len)
rules iterate (1300) until (instr(sqnc[iteration_number],'~')! = 0)
(sqnc [iteration_number] = case when sqnc [cv (i) - 1] is null
then sqnc [0]
of another substr (sqnc [iteration_number - 1], 1, 1) |
-case when substr (sqnc [iteration_number - 1], 2, 1)<=>=>
so when business substr (sqnc [iteration_number - 1], 3, 1)<>
then substr (ordr [0], instr (ordr [0], substr (sqnc [iteration_number - 1], 2, 1)), 1)
of another nvl (substr (ordr [0], instr (ordr [0], substr (sqnc [iteration_number - 1], 2, 1)) + 1.1),'~ ')
end
end |
-case when substr (sqnc [iteration_number - 1], 3, 1)<>
then substr (ordr [0], instr (ordr [0], substr (sqnc [iteration_number - 1], 3, 1)) + 1.1)
else ' 0'
end
end
)
)
where instr(sqnc,'~') = 0
Concerning
Etbin
-
How to generate the sequence Island-1, -1, 1, 1...
How to generate the sequence Island-1, -1, 1, 1...This seems to work:
create sequence sss start with -1 increment by 2 minvalue -1 maxvalue 1 cycle nocache;
-
Generate a sequence based on a number
I have two tables... I want to generate the sequence 01, 02, etc., based on total_sections
Table 1:
CourseID Total_sections
1 101
1 102
3 103
2 104
I would like to create a table based on the table above and the result should look like:
CourseID Section_Num
101 01
102 01
103 01
103 02
103 03
104 01
104 02
How can I achieve this?And two more :)
With 11g recursive subquery factoring:
WITH t (course, number_of_sections, section_num) AS ( SELECT course, number_of_sections, 1 FROM your_table UNION ALL SELECT course, number_of_sections, section_num+1 FROM t WHERE section_num < number_of_sections ) SELECT course, to_char(section_num, '09') as section_num FROM t ;
With a bit of XML:
SELECT t.course, to_char(x.num,'09') as section_num FROM your_table t, XMLTable( '1 to xs:integer($n)' passing t.number_of_sections as "n" columns num for ordinality ) x ;
-
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, ...) ;
-
To generate the sequence in the select clause of the inner query
Hi all
Have the table and the data as below,
I want to generate a sequence number for all the distinct combinations of emp_id and emp_name running
DROP TABLE emp1.
CREATE TABLE emp1 (emp_id NUMBER, emp_name VARCHAR2 (100));
INSERT INTO emp1 VALUES (1, 'Name1');
INSERT INTO emp1 VALUES (2, 'Name2');
INSERT INTO emp1 VALUES (1, 'Name3');
INSERT INTO emp1 VALUES (2, 'Conjoint4');
COMMIT;
Output must be same as below:
EMP_ID EMP_NAME Reference ID 1 Name1 1000 1 Name1 1000 1 Name3 1001 2 Name4 1002 2 Name2 1003 "You cannot invoke CURRVAL and NEXTVAL in the subquery to CREATE."
"MATERIALIZED VIEW, or a SELECT, UPDATE, or DELETE statement;
Steve O'Hearn, Guide to preparing Oracle 1Z0-047
------
-
need help to generate the sequence
HII all I want to generate a sequence, but I am not able to generate
the logic is that I must have values such as c11, c12... c199
and then A1, A2, A3, A4... A9, B1... B9, C1... C9... Z9
I WROTE AFTER THE CODE, BUT IT IS NOT WORKING CAN YOU HELP ME PLEASE
Published by: 810345 on May 19, 2011 15:51CREATE TABLE ABC(NAME VARCHAR2(100)); declare v_t varchar2(10) ; j number ; i number; v_t1 char := 'A'; type t11 is table of varchar2(3000) index by binary_integer; t1 t11; begin execute immediate('truncate table abc'); for n in 1..99 loop t1(n) := 'c1'||i; insert into abc values(t1(n)); commit; end loop; loop ---to convert j:=1; loop v_t := v_t1||j; j := j+1;---1to 9 insert into abc values(v_t); commit; exit when j = 10; end loop; exit when ascii(v_t1) = ascii('Z') and j =9; v_t1 := chr(ascii(v_t1)+1); end loop; end;
that's about it:
CREATE TABLE abc (name VARCHAR2 (100)); TRUNCATE TABLE abc; -- whenever possible never put ddl-code into a pl/sql-block DECLARE BEGIN FOR n IN 1 .. 99 LOOP INSERT INTO abc VALUES ('C1' || n); END LOOP; FOR j IN ASCII('A') .. ASCII('Z') LOOP FOR k IN 1 .. 9 LOOP INSERT INTO abc VALUES (CHR(j) || k); END LOOP; END LOOP; COMMIT; END; /
-
Generator of sequence numbers for any number of PDF forms
Hello
With the help of this forum, I now have a simple Workbench process that acts as a Web service to generate a sequence number.
When it is called by a PDF form it reads a value in a database, increment the value and then reads the db to return the value incremented to the form.
It works fine, but now I need something else: I have about 60 forms and each will have its own sequence.
The way I see what I have to do is:
-include a new column in the db table to store the IDs forms (I already did).
-modify the SQL statements to include the number of Ref form as a parameter of a WHERE clause (I already did).
and...
-Send the Ref form number from the PDF file during the call to the web service. = > I have not yet figured out how do.
-receive this Ref number in the workbench to use as a parameter in the WHERE clause.
Please could someone help me out here? Or point to a few examples online that I could use as a guide?
Will I receive the news of the PDF in the form of XML file and extract the info from its structure?
Thanks much for the advice.
Marcos
Hello
Any variables created within a process are accessible by all of the finding.
You don't need to associate the value through the extra activity.
for example you can directly use the value of the variable in the SQL activity to increment & get the next number in the sequence.
Note that you must not even two activities SQL to do. A single SQL activity can execute multiple SQL queries.
Hope that helps.
Nith
-
Automatically generate the sequence
I work with several scripting on a project and we have a lot of sequences to write. We are working on a standard for our test procedures to bring them as easy as possible. I spent a little time to play with the property import/export function today and wanted to see the feasibility of generation a sequence from a CSV, xml, excel, files etc.
Is it possible to build the sequence from an external file? We primarily interface with LabVIEW live (and specify the settings) and compared with the planned values. We have a few loops and calendar items, but not much.
I prefer to use TestStand 3.5 it is the version used by most of our writers, but would be willing to update if necessary. I just want to see if this is possible, before working on a new format.
-DH
Hello
Have you looked at the example that comes with TestStand. Its a simple example that creates a sequence from a text file.
concerning
Ray Farmer
-
generate the sequence of number
Hello
By request, below I want to automate the SQL below such that she will work for the coming year without touching (from 2011)
e.g. year marked after the keyword (APPLE). i.e. 2011, 2012, 2013 etc.
For the coming year, I'm still updaing the program by adding a condition to the program. This means that for the next year 2015, I should add as condition (or phone laptop like '% APPLE2015') that I don't want.
with abc as
(
Select 1010 as id, 'APPLE20100123' like mobile double
Union
Select 1011 as id, 'APPLE20080125' like mobile double
Union
Select 1012 as id, 'APPLE20110123' like mobile double
Union
Select 1013 as id, 'APPLE20120123' like mobile double
Union
Select 1014 as id, 'APPLE20130123' like mobile double
Union
Select 1015 as id, 'APPLE20140123' like mobile double
Union
Select 2012 as id, 'APPLE20110153' like mobile double
)
Select * from ABC
where
phone portable like '% APPLE2011 '.
or
phone portable like '% APPLE2012 '.
or
phone portable like '% APPLE2013 '.
or
phone portable like '% APPLE2014 '.
You can do it.
where substr(cellphone, 1, 5) = 'APPLE' and to_number(substr(cellphone, 6, 4)) >= 2011
If necessary to create a feature based on the same index.
-
Code temporal list/table to generate the sequence?
I have a list of time codes based on a sequence of clips, essentially all of the dailies less certain camera wobbles.
I want to generate a new sequence of this temporal/worksheet code listing without having to manually change. Any ideas?
Once you could just drill timecodes in FCP7 and the system would recover the band/clips using the list of timecode.
Thank you
Jay
It's the bit by hand as I try to avoid.
We get that. I don't think it's possible.
-
How to generate the sequence of grid
I have 1 page
and the order like that
level 0 MYHeader_table
Level1 MYHeader_table scrolling region
Level2 grid MYDetail_table
How I gerenate MYDetail_table.seq in RowInsert sequenceYou must add the code to your peoplecode rowinsert.
example:
MyDetail_table.seq.value = MyDetail_table.seq.value + 1;
also, why do you myheader_table Level0 and level1, it is a bad design.
-
Number of the sequence in the form of the ADF.
Hi all
I have a table with ID as primary key and have a sequence created for the primary key and have a trigger to generate the sequence number when the record is inserted in the table.
How can I map this sequence in the ADF so when inserting record in the form I can skip the ID column.
Kind regards
Suresh kumarChange the attribute of the entity and assign it the value
(new oracle.jbo.server.SequenceImpl ("YOUR_SEQ", object.getDBTransaction ()) .getSequenceNumber)
Maybe you are looking for
-
Problems with wifi: Broadcom BCM43142 802.11 bgn adapter WiFi in Windows 10 Pro
Hi, I have some problems with my laptop wifi card. Product of my cell phone number is: L8R39AV. Therefore my main problem in my laptop that my wifi card is a bit faulty. Defective in this sense, it is slow compared to the connection with the wired et
-
Should what cable I plug my Satellite P200-155 to a TV?
For a while thinking about it but I don't know which cable is that I need? Thanks for the help!
-
17i wanted to replace SSD HARD drive
I just bought a new screen Envy 17 t tactile image with a 1 TB HARD drive 5400 RPM. At the same time, I bought a new Samsung 840EVO 500 GB SSD with the intention to replace the slower HARD disk with the fastest SSD. I thought it would be a simple swi
-
my Skype crashes whenever I click on one - I rebooted and also uninstalled and reinstalled several times
-
Windows XP - laptop computer purchase on eBay and o/s has no validation
I'm helping a friend and now I need help. The friend bought a laptop Compaq from eBay. Installation of a USB adapter in the computer wireless laptop and decided also do updates of Microsoft security and introduce an anti-virus because it was not one