Generate a sequence of number

Hi i am using
select rownum rn from user_objects where rownum <= 20;
to generate a sequence of number....
is there any other better way...???

try
select level
from dual
connect by level <= 20;
illustrated at -
http://nimishgarg.blogspot.com/2010/01/oracle-sql-get-all-month-names-jan-to.html

Similar Messages

  • Select from table in group of columns and generate a sequence number

    I have to select data from a table in group of columns and generate a sequence for every group resetting the sequence to start from 1 onwards.
    For example:
    Data:
    Col1 Col2 Col3 Col4
    A NA KA 2009-08-13
    B NA KA 2009-08-13
    C NA KA 2009-08-13
    A NA KA 2009-08-13
    B NA KA 2009-08-13
    A NA KA 2009-08-13
    Expected output from Select Statement:
    Col1 Col2 Col3 Col4 Seq_No
    A NA KA 2009-08-13 1
    A NA KA 2009-08-13 2
    A NA KA 2009-08-13 3
    B NA KA 2009-08-13 1
    B NA KA 2009-08-13 2
    C NA KA 2009-08-13 1
    How can this be possible with a SELECT statement? Is it possible to assign seq numbers for a group of columns and reset it when it changes? In the above example, all columns form the key to generate the seq number
    I know it can be done using Stored procedures and that is how I am doing it now by introducing a temporary table.
    Can anyone help me in this regard? Please let me know if the question is vague to understand!
    Thanks,
    Nachi

    with t as(select 'A' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'B' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'C' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'A' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'B' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'A' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual)
    select t.*,row_number() over (partition by col1,col2,col3,col4 order by col1,col2,col3,col4) from tYou can replace partition by col1,col2,col3,col4 with only columns that you need for grouping condition
    and also order by you can just do on the column you need.

  • 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 Cochrane

    Hi,
    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,

  • Calculate date differences in consecutive rows and generate a sequence

    Hi Guys,
    I am trying to implement one scenario where in i need to compare the date differences for consecutive rows and generate a sequence against that.
    this is the table schema:
    create table temp
    id int identity(1,1),
    emp_id int,
    time datetime
    insert into temp 
    values
    (1, '2011-02-20 12:30:00.000'),
    (1, '2011-02-20 12:32:34.172'),
    (1, '2011-02-20 12:32:34.172'),
    (1, '2011-02-20 12:43:21.004'),
    (1, '2011-02-20 12:46:39.745'),
    (2, '2011-02-20 12:48:06.004'),
    (2, '2011-02-20 12:48:06.004'),
    (2, '2011-02-20 12:53:07.733'),
    (2, '2011-02-20 12:55:30.295');
    now, I want to compare the first date-time with the second and so on. now if the date-time difference is same for two consecutive rows then the sequence should  increment by 1 otherwise the sequence again will start from '00' for any unique date-time.
    This sequence number should start from '00' from each employee.
    I want the output to be like this
    ID emp_id
    time    
    sequence
    1 1 2011-02-20 12:30:00.000
    00
    2  1 2011-02-20 12:32:34.172
    00
    3  1 2011-02-20 12:32:34.172
    01
    4  1 2011-02-20 12:32:34.172
    02
    5  1 2011-02-20 12:46:39.745
    00
    6  2 
    2011-02-20 12:48:06.004 00
    7  2 
    2011-02-20 12:48:07.003 00
    8  2 
    2011-02-20 12:48:07.003 01
    9  2 
    2011-02-20 12:46:39.745 00
    Please revert as soon as possible as this is a bit urgent.
    Thank You in Advance. :)

    create table temp
    (id int identity(1,1),
     emp_id int,
     time datetime
    insert into temp values
    (1, '20110220 12:30:00.000'),
    (1, '20110220 12:32:34.172'),
    (1, '20110220 12:32:34.172'),
    (1, '20110220 12:43:21.004'),
    (1, '20110220 12:46:39.745'),
    (2, '20110220 12:48:06.004'),
    (2, '20110220 12:48:06.004'),
    (2, '20110220 12:53:07.733'),
    (2, '20110220 12:55:30.295');
    go
    SELECT id, emp_id, time,
           dateadd(mcs, (row_number() OVER(PARTITION BY emp_id, time ORDER BY
    id) - 1) * 10,
                   convert(datetime2(5), time)) AS [Sequence]
    FROM   temp
    ORDER  BY id
    go
    DROP TABLE temp
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to generate random sequence numbers

    Hello experts
    Iu2019m writing a custom program and pulling data from VBAK & VBAP. As per requirement I also need to generate a sequence number randomly and finally store all data in text file and upload at server. The hiccup is I donu2019t know how to generate sequence numbers. Can somebody please show me how I can accomplish it?
    Thanks a lot in advance

    Find the below code,
      data: lv_range type datatype-char0128.
      call function 'RANDOM_C'
        exporting
          len_min   = 20
          len_max   = 20
          char_min  = 1
          char_max  = 20
        importing
          rnd_value = lv_range.
    LV_RANGE param will have a random value..
    If you need number you can use the FM "RANDOM_I4"
    Thanks,
    Prathap

  • Generating a sequence of waveforms with NI 5640R card

    Hello,
    I have a question regarding generating a sequence of waveforms. I want to use the example "NI 5640R analog input and output" (I know this example is capable of generating a QAM or single tone signal) and make changes such that the when i run the VI i want the output to be switching between single tone and QAM and i want this to happen until i stop the VI.
    And in the future i want to add another waveform (sawtooth) and want my output to be switching between the 3 waveforms. Any help regarding this will be grately appreciated.
    Thanks,
    Sandeep. 
    Sandeep Palreddy, Graduate Research Assistance
    The Microwave Remote Sensing Laboratory (MIRSL)
    University of Massachusetts
    151 Holdsworth Way
    Amherst MA 01003-9284

    Hello,
    I have a question regarding generating a sequence of waveforms. I want to use the example "NI 5640R analog input and output" (I know this example is capable of generating a QAM or single tone signal) and make changes such that the when i run the VI i want the output to be switching between single tone and QAM and i want this to happen until i stop the VI.
    And in the future i want to add another waveform (sawtooth) and want my output to be switching between the 3 waveforms. Any help regarding this will be grately appreciated.
    Thanks,
    Sandeep. 
    Sandeep Palreddy, Graduate Research Assistance
    The Microwave Remote Sensing Laboratory (MIRSL)
    University of Massachusetts
    151 Holdsworth Way
    Amherst MA 01003-9284

  • Unsupported generator type: SEQUENCE

    Is the primary key generation strategy "SEQUENCE" supported? I have an entity, based on a table in Oracle database, whose primary key is generated by a sequence in Oracle database. When I deploy the entity I get the following error...
    ORPersistence Model Builder: Exception occurred: com.sap.engine.services.orpersistence.model.ormappingmodel.ORMException: Unsupported generator type: SEQUENCE at com.sap.engine.services.orpersistence.model.ormappingmodel.impl.ORMappingModelCreatorImpl.parseId(ORMappingModelCreatorImpl.java:2347), file: EntityTest.jar, column 0, line 0, severity: error

    Hi Christopher,
    The generation types SEQUENCE and IDENTITY are currently not supported by the JPA implementation in this release. You can however use the TABLE and AUTO generation types. In the case of AUTO you have to provide a table TMP_SEQUENCE created like this:
    CREATE TABLE "TMP_SEQUENCE"
    "GEN_KEY" VARCHAR(256) UNICODE NOT NULL,
    "GEN_VALUE" INTEGER,
    PRIMARY KEY ("GEN_KEY")
    HTH!
    -Vladimir

  • How to generate an incrementing batch-number per set number of rows

    Hi,
    How could you generate an incrementing batch-number per set number of rows for a table in SQL?
    The returned result set of the SQL query should show a preceding batch number per row set and incremented by 1 for the next row set.
    Eg, you want to start the batch_number by 1 for the first three returned rows of the table and than increment by 1 for the next three rows.
    The result set would look like:
    BATCH_NO, TAB_COL1, TAB_COL2, TAB_COL3, TAB_COL4, ..
    1, ...
    1, ...
    1, ...
    2, ...
    2, ...
    2, ...
    3, ...
    3, ...
    3, ...
    etc.
    Cheers.

    Many thanks guys, I would have never thought about these options.. Yes the reason for adding the preceding batch number has to do with migrating data from a source table where we only can grab small sets of rows at the time to bring across to a target table.
    Cheers.

  • Display sequence serial number.

    i need help to solve my problem how to display sequence serial number if its content alphabet. Given an example: starting serial number AA0003 and ending serial number is AA0010.

    This is the wrong forum to discuss , better look out for beginners in Java

  • Generating N-digit random number??

    Hi All,
    I need to generate N-digit random number, anyone can help me?
    Thx in advance b4...

    import java.util.*;
    public class Try{
         public static void main(String []args){
              for(int i=0;i<100;i++){
                    System.out.println((int)(Math.random() * 10));
    }Yes I saw the casting, no problem with it, but I did used it alot to generate me number between a range of 1 - 9
    and if you want a range of 1 - 10, i just put a
    1+(int)(Math.random() * 10)

  • How to alter sequence next number

    Can we alter sequence next number. I want to start it from minval.

    To restart the sequence at a different number, you must drop and re-create it.
    If you change the INCREMENT BY value before the first invocation of NEXTVAL, some sequence numbers will be skipped. Therefore, if you want to retain the original START WITH value, you must drop the sequence and re-create it with the original START WITH value and the new INCREMENT BY value.
    Oracle Database performs some validations. For example, a new MAXVALUE cannot be imposed that is less than the current sequence number.

  • "How do I generate a sequence of waveforms, like first a sine wave, then a square one, and say again a sine wave?"

    "Hello everyone, I hope someone can answer the following question. How do I generate a sequence of different waveforms, with different attributes?
    Like, i want to generate a sine wave for some time, then a square pulse of some width and then again a sine wave of some other time. Finally I want to repeat this sequence. I'll really appreciated it if I can get an answer soon. Thank you!

    From the previous comments I am assuming that your waveforms are arrays, rather than the waveform data type. I am also assuming that the sine waves on both sides of the square wave are the same signal.
    If so then I suggest a slightly different approach. 1. Generate your sine wave, rather than the empty array. The length should be the length of the entire end signal.
    2. Generate the square waveform. You can either generate it at the length you need, or you can generate a much larger square wave, and then use the Array Subset VI to get the portion you need. Which method you use depends how you want to implement the whole method.
    3. Use the Replace Array Subset VI to place the portion of the square wave at the location (index) of the original sine wave you ge
    nerated.
    The result of this method will be an array that starts with your sine wave, and then at the index you choose it will place the square wave of the length you want right into the signal, and then finish up with the sine wave for the rest of the signal.
    Evan Collier
    Application Engineering
    National Instruments

  • Generate alphanumeric sequence using oracle sequence

    Hi,
    Can we generate alphanumeric sequence from Oracle sequence.
    Sequence would be something like this. Please advice
    TEMP-0001
    TEMP-0002
    TEMP-0010
    Thanks,
    Lak

    hi,
    You can try below procedure...
    SQL> create sequence sec
      2  minvalue 0
      3  start with 001
      4  increment by 1
      5  nocache;
    Sequence created.
    SQL> select 'temp-'||to_char(sec.nextval) from dual;
    'TEMP-'||TO_CHAR(SEC.NEXTVAL)
    temp-1

  • How can we generate auto Sequence Number in DFF attribute

    Dear
    We are on r12,rignt now we have an issue to generate sequence number in site Level(DFF) on Supplier window,actully we want
    to generate sequence number on site leve while inserting new record on site level,so how could i achvie this or any way which can help us.
    --thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You can consider writing a before-insert trigger.
    The trigger generates the next value of the sequence and makes :new.attributen = the sequence value.
    Hope this helps,
    Sandeep Gandhi

  • Need to generate unique sequence number based on category

    Hi,
    I have to update the NEW_NUMBER column  with unique number ,taking into category column consideration.
    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 into sample values('RESISTOR','46858','');
    insert into sample values('RESISTOR','47858','');
    insert into sample values('RESISTOR','46958','');
    {code}
    I have to update the NEW_NUMBER column  with unique number ,taking into category column consideration.
    Output would be like this.
    {code}
    insert into sample values('CAPACITOR','36858','270-01-0000001');
    insert into sample values('CAPACITOR','37858','270-01-0000002');
    insert into sample values('CAPACITOR','36958','270-01-0000003');
    insert into sample values('RESISTOR','46858','370-01-0000001');
    insert into sample values('RESISTOR','47858','370-01-0000002');
    insert into sample values('RESISTOR','46958','370-01-0000003');
    {code}
    If you can help to generate for one category,I will do it for other categories.
    Thanks in advance.
    Thanks,
    Lak

    Not sure how you came up with 270 and 370. But with what ever information you have provided this is what i came up with.
    SQL> select * from sample;
    CATEGORY   OLD_NUMBER           NEW_NUMBER
    CAPACITOR  36858
    CAPACITOR  37858
    CAPACITOR  36958
    RESISTOR   46858
    RESISTOR   47858
    RESISTOR   46958
    6 rows selected.
    SQL> merge into sample a
      2  using (
      3          select category
      4               , old_number
      5               , decode(category, 'CAPACITOR', '270', 'RESISTOR', '370')
      6                 || '-01-'
      7                 || lpad
      8                    (
      9                       row_number() over(partition by category order by old_number)
    10                     , 7
    11                     , '0'
    12                    ) new_number
    13            from sample
    14        ) b
    15     on (
    16          a.category   = 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 rows merged.
    SQL> select * from sample order by category, old_number;
    CATEGORY   OLD_NUMBER           NEW_NUMBER
    CAPACITOR  36858                270-01-0000001
    CAPACITOR  36958                270-01-0000002
    CAPACITOR  37858                270-01-0000003
    RESISTOR   46858                370-01-0000001
    RESISTOR   46958                370-01-0000002
    RESISTOR   47858                370-01-0000003
    6 rows selected.

Maybe you are looking for

  • How do I automatically upload files to an FTP server with Compressor 4?

    So I've been using Compressor 4 in order to compress some videos into a manageable size for streaming. However, I've been trying to figure out how to set up an automatic FTP upload to the program Transmit through Compressor 4, but have been running i

  • Business Smartphone and only 3 Languages?

    So far I understand is this Forum official from Blackberry. And therefore I hope that some official key people from Blackberry read here with us. I just moved from iPhone to Blackberry Z10 for different reasons. One reason was the fact that apple don

  • Help BC win the CMS Critics Choice Awards!

    Hi everyone, Business Catalyst, the CMS you all love to use, has just been nominated in 2 different categories in the CMS Critics Choice awards. Voting for the competition has started yesterday, and will go on through September 30th. Help us win the

  • SharePoint 2013 - CQWP include child content types issue

    Hello SharePoint enthousiastes, I'm experimenting a weird issue with the content query webpart in SharePoint 2013. In the query part of the webpart settings, in the Content type section, I want to untick the "Include child content types" option > Con

  • Problem possibly with actionListener

    Hello, I am developing a GUI appplication with Java 1.4.2 and Netbeans 5. I have created a jtree whose status changes from visible to invisible. The first time that it is visible it works correctly, the second time (after making it invisible and agai