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
;

Tags: Database

Similar Questions

  • need to generate unique sequence for each transaction number

    need to generate unique sequence for each transaction number

    Use sometihng like that



    use the orcl: sequence-next function val

  • 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

  • Generate the sequence of random by number

    How to generate random random 4 digit number using the sequence or any other method. Please suggest

    Take a look at http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_random.htm#ARPLS040

    Concerning

    Etbin

  • Generate the sequence number

    
    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.

  • Select the table column group and generate a sequence number

    I have to select data from a table column group and generate a sequence for every reset of the sequence from 1 to leave.

    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 results of the 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 it be possible with a SELECT statement? Is it possible to assign the following numbers for a group of columns and put it back when it changes? In the above example, all columns are the key to generate the seq number

    I know that this can be done using procedures stored and that is how I do it now by introducing a temporary table.

    Can someone help me with this? Please let me know if the question is too vague to understand!

    Thank you
    Nachi

    Use the row_number() analytics.

    Ravi Kumar

  • Generate a sequence of number

    Hi I am using

    Select rownum rn from user_objects where rownum < = 20;

    to generate a sequence of numbers...

    is there another better way...?

    Try

    Select the level
    of the double
    connect by level<=>

    illustrated in the.
    http://nimishgarg.blogspot.com/2010/01/Oracle-SQL-get-all-month-names-Jan-to.html

  • 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_IDEMP_NAMEReference ID
    1Name11000
    1Name11000
    1Name31001
    2Name41002
    2Name21003

    "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

    ------

  • Generate the series based on the column

    Hi Experts,

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

    PL/SQL Release 9.2.0.1.0 - Production

    Could you please help me to generate the folloing sequence.

    act_noto_be
    11
    02
    12
    12
    03
    13
    04
    14
    14
    14
    05
    15
    15
    15
    15
    15

    Based on the act_no I want to generate the sequence to_be in sql.  Help, please.  Thanks in advance.

    You must have a column that defines the order of the line. I added a column ID that defines the order of the single column. With this you can do.

    SQL > t
    2 as
    (3)
    4. Select 1 id, 1 act_no Union double all the
    5 select id 2, act_no 0 of all the double union
    6 select id 3, 1 act_no Union double all the
    7 select id 4, 1 act_no Union double all the
    8 select id 5, 0 act_no of all the double union
    9 select id 6, 1 act_no of all the double union
    10. select id 7, 0 act_no of all the double union
    11 select id 8, 1 act_no Union double all the
    12. select id 9, 1 act_no of all the double union
    13. select id 10, 1 act_no of all the double union
    14 select id 11, 0 act_no of all the double union
    15 select 12 id, 1 act_no of all the double union
    16. select id 13, 1 act_no of all the double union
    17 select id 14, 1 act_no of all the double union
    18 select id 15, 1 act_no of all the double union
    19 select id 16, 1 double act_no
    20)
    21 select t.id
    22, t.act_no
    23, max (t1.rno) on to_be (t.id control)
    24 t
    25 left
    Join the 26)
    27 select row_number() over (order by id) rno
    28                 , id
    29, act_no
    30 t
    31 where act_no = 0 or (id = 1 and act_no = 1)
    (32) t1
    33 on t.id = t1.id
    order of 34
    35 by id;

    ID ACT_NO TO_BE
    ---------- ---------- ----------


    1          1          1
    2          0          2
    3          1          2
    4          1          2
    5          0          3
    6          1          3
    7          0          4
    8          1          4
    9          1          4
    10          1          4
    11          0          5
    12          1          5
    13          1          5
    14          1          5
    15          1          5
    16          1          5

    16 selected lines.

    SQL >

  • You can customize the number of forms that are based on a number that you enter?

    Hello

    I try to combine two forms: forms of recording and registration of attendance.  The record attendance would list all students, and the registration forms would be student specific.  I wonder if there is a way that I can enter in the number of students on attendance record, and that the required number of forms would generate registration based on this number.

    A lesson in models for Adobe Acrobat by Dave Wraight

  • Increment sequence based on the existence value

    Hello

    I have a requirement,
    I need the value sequence based on the values exist in the database.
    Let me explain with an example of a column, I have values such as 1,2,3,4,5,6,7,8,10,12,14, etc...

    Here I have to generate the value of the sequence 9,11,13 follows...


    Logically it please suggest me... I try with While loop I could not reach again.

    We want to help you.

    Concerning
    Rambeau
     select  level missing_values
       from  dual
       connect by level <= (select max(your_column) from your_table)
    minus
     select  your_column
       from  your_table
    /
    

    For example:

    with t as (
               select level n from dual connect by level < 9 union all
               select 10 from dual union all
               select 12 from dual union all
               select 14 from dual
              )
    -- end of on-the-fly data sample
     select  level missing_values
       from  dual
       connect by level <= (select max(n) from t)
    minus
     select  *
       from  t
    /
    
    MISSING_VALUES
    --------------
                 9
                11
                13
    
    SQL> 
    

    SY.

  • 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

    CREATE 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;
    Published by: 810345 on May 19, 2011 15:51

    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;
    /
    
  • Automatically load a sequence based entered digital file to USE

    Hello

    I have question where I need to test 8 different DUT, one at a time, but it should automatically load the sequence file based on the digital inputs of the connection block of the UUT.  Each object to be measured has a coonector to the construction of the box where all the e / s is related to the material OR

    3 specific entries of my digital I/o card will show that USE is connected.  When the object to be measured is connected to a card the next logical state of e/o / s will tell USE which must be tested.

    0 0 0--> UUT 1

    0 0 1--> UUT 2

    0 1 0--> UUT 3

    1 1 0--> DUT 4

    1 0 0--> UUT 5

    1 0 1--> UUT 6

    1 1 0--> UUT 7

    1 1 1--> UUT 8

    How testand can load the specific sequence based on above of the digital I/o logic States. Can it be done in the process template? I am also building a simple operator TS interface on labview.

    Concerning

    VERP

    You will need to create a code for this function. You will need to read these digital I/o, select the file in the appropriate sequence.

    You need to open this file in sequence by using the ApplicationMgr.OpenSequenceFile method.

    Set the SequenceFileViewMgr.SequenceFile property with the open movie file reference. Then when you press the buttons of the chosen sequence Entry Point will be executed.

  • 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

    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

  • Calculate fees that pay based on the number of days in a month

    Hello

    I'm writing the BR to fresh wages, based on the number of days in the month.

    Fix(Jan:DEC)

    "Salary" = ("Annual salary"-> "BegBalance" / 12) * "workforce";

    The existing calculation was ' wages divided by months no .of (12) ", now instead of number months wages that need to be calculated ("BegBalance"/ No..) OF DAYS IN THE MONTH) * 12.

    Can someone pls guide me, how to begin writing the BR for 'No. DAYS OF THE MONTH.

    You can do an admin enter number of days in the month. I remember CL reminding me the rhyme thirty days has September - Wikipedia, the free encyclopedia

    Jokes aside, you can use SQL to get the number of days. You will get different options for SQL and Oracle.

    If you want to continue to do this in BR then

    Fix(Jan:DEC)

    IF (@ISMBR (SEP) OR @ISMBR (Apr) OR @ISMBR (Jun) OR @ISMBR (Nov))

    ("Salary" = ("annual salary"-> "BegBalance" / 30) * 12) * "workforce";

    ELSEIF (@ISMBR (Jan) OR @ISMBR (Mar) OR @ISMBR (May) OR @ISMBR (July) OR @ISMBR (Aug))

    ("Salary" = ("annual salary"-> "BegBalance" / 31) * 12) * "workforce";

    ELSE (@ISMBR (Feb))

    IF (@Remainder($CurrYr/4) == 0)

    ("Salary" = ("annual salary"-> "BegBalance" / 29) * 12) * "workforce";

    ON THE OTHER

    ("Salary" = ("annual salary"-> "BegBalance" / 28) * 12) * "workforce";

    ENDIF

    ENDIF

    ENDFIX

    Concerning

    Celvin

    http://www.orahyplabs.com

    Post edited by: CelvinKattookaran

Maybe you are looking for