Extend each line to the new lines by "N".

Oracle 11.2.0.1

Here's a simple query that develops each line given in "N" new lines with a sequence counts 1 to "N", where "N" is given as the column 'cnt '.

It works and gives the expected results, as shown below; but I wonder if there is a more effective or more elegant way to do this. I really don't like the cross all lines of the largest sequence in the data join.

with smpl_data as
  ( select  'item-1' val, 3 cnt  from dual union all
    select  'item-2'    , 4      from dual union all
    select  'item-3'    , 1      from dual union all
    select  'item-4'    , 0      from dual union all
    select  'item-5'    , 2      from dual 
  )
select  a.val, b.n
  from  smpl_data  a
        cross join
        ( select  level as n 
            from  dual 
          connect by level <= (select max(cnt) from smpl_data) 
        )  b   
 where  b.n <= a.cnt
 order  by  a.val, b.n ;

Results:

    VAL         CNT
    ------  ---
    item-1  1
    item-1  2
    item-1  3
    item-2  1
    item-2  2
    item-2  3
    item-2  4
    item-3  1
    item-5  1
    item-5  2
Thank you.

Since you're on 11g the WITH recursive clause is better (and should be faster too).

Here's how you can use it.

with smpl_data (val, cnt) as
  ( select  'item-1', 3 from dual union all
    select  'item-2', 4      from dual union all
    select  'item-3', 1      from dual union all
    select  'item-4', 0      from dual union all
    select  'item-5', 2      from dual
  )
 ,data_expand (val, cnt)
   as (select d1.val, d1.cnt from smpl_data d1
       where d1.cnt > 0
       UNION ALL
       select d2.val, d2.cnt-1 from data_expand d2
       where d2.cnt > 1
       )
select * from data_expand
order by val, cnt
;

val   cnt
----------
item-1     1
item-1     2
item-1     3
item-2     1
item-2     2
item-2     3
item-2     4
item-3     1
item-5     1
item-5     2

Published by: Sven w. on 12 July 2012 16:30
-changed: output 0 rows are excluded

Tags: Database

Similar Questions

  • [WS10] Each linux discovers the new NIC-boot...

    Hello

    I have a Windows 2008 R2 host with 10 VMWorkstation and a SLES 9.3 (very old, it the origins of a virtualized physical machine) as a guest.

    So now the problem is the following:

    When I start first sles (yast) system detects the network adapter for vmware (bridged mode by the way) - it shows as 'AMD PCnet - FAST 79C971' (hardware-configuration-name: bus - pci - 0000:02:00.0, modulname: vmnic).

    I cannot set up then and also assign and IP address him. The network works 100% then - until I restart.

    When I go into the yast after the reboot, the old card is still there and set up (but not recognized more I think)- but there is also a new card which is exactly the same as before.

    If I configure this network does not work yet. What I need to do to make it work again is: remove all cards configured, restart once more and then assign an IP address to the detected map (which is the same as in the "first step" above).

    No idea if this can be fixed? Or the sles is all just too old?

    By the way: before I had a SLES 11 as the host system and where the network is still working on this machine.

    It is possible to misconfigure the vmx file so that every time he gets a new address MAC - sp check your settings

  • How the BPEL file adapter to read only the new files?

    Hello


    We have BPEL processes that define to execute bpel component - file adatper-

    When a file entered in the place that it is the path on the linux server. the beginning of bpel run what component bpel "File adapter" recognize this new file come to the location. its PollingFrequency set to 5. name of the property = "DeleteFile" value = "false" If the fleeting files there.

    We want to migrate the bpel new SOA version, so we did export and deploy SOA field again.

    the location of the file adapter is the same.

    but when the process BPEL deployment began to run for all the files that are in this situation - which define the file adapter.

    even the original soa tooks these files and start the BPEL processes for each of them. the new SOA which did us deploy BPEL processes takes advantage of these files even if they are very old.

    We want the adatper file we take only new files. the starting point is the time where we deploy the process so if we spread out at 10:00 we do not want this bpel will be from 09:00 or before the files

    Please help, how we can do this?

    Thank you

    Adapter JCA files/FTP Oracle - 11g Release 1 (11.1.1.6.2)

    Incoming headers

    Outside the payload file Oracle adapter publishes metadata for next header, with the incoming service, as shown in Figure 4-24:

    • jca.file.FileName: file name
    • jca.file.Directory: the directory name
    • jca.file.Batch: a unique name for a batch if debatching
    • jca.file.BatchIndex: index of batch for each message in the batch for debatching
    • jca.file.Size: the size of the file
    • jca.file.LastModifiedTime: the file was last modified

    Capture the jca.file.LastModifiedTime compare with any time is necessary. If jca.file.LastModifiedTime< 10:00="" am="" then="" do="" not="" action,="" else="" perform="" the="">

  • The new Records real-time display

    I developed a CRM that is based on this post to a database of prospects.  The CRM index page performs a select query and displays a filtered recordset based on the SQL code.  This index page is updated every 30 seconds by an update of the Meta tag.  But I think there must be a more robust and efficient method.  Ideally, I would like to have a popup is displayed each time that the new record messages when clicked would reveal the details of the record.  And if such a robust method exists, which could better the overall updating of the data other than a Meta Refresh?  Any direction you can advise would be appreciated.
    .

    Some of which can easily be done with JavaScript and a function that makes calls to ColdFusion AJAX to check new records, on a timer (30 seconds).  You can use WebSockets which offers the display in real time, but according to the rate of data change, which might be overkill.

    For example, look at how this site or Google followed new messages using AJAX. If you are connected to these forums, your avatar at the top of the screen may have a white number in an orange circle to the left of the avatar - stating that you have new messages or updates waiting for your attention.  If you have no messages or elements, the circle disappears.  While new messages or items arrive in your Inbox, reappears in the circle and the number will change.  This is done via AJAX requests that ask the service Inbox on a given time interval. In your application, you will need to decide what is the appropriate interval (or make a user setting which gives them options such as 30 seconds, 1 minute, 5 minutes, etc.).

    All this is done without refreshing the entire page (what does refresh Meta Tag).

  • I have a column with two values, separated by a space, in each line. How to create 2 new columns with the first value in a column, and the second value in another column?

    I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?

    Add two new columns after than the original with space separated values column.

    Select cell B1 and type (or copy and paste it here) the formula:

    = IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    shortcut for this is:

    B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")

    or

    the formula of the C1 could also be:

    = IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")

    Select cells B1 and C1, copy

    Select cells B1 at the end of the C column, paste

  • Use: OLD and: NEWS in the triggers without oracle for each line

    I use Oracle 10 g.
    I want to insert a row in the table of the newspaper by each Witch of the query is executed on a table.
    And I want to insert on the line at a table of detailed log for each row changed in a query.
    I want to add modification date and time for each line in the two tables of the newspaper and I want it to be similar.

    So, I'm curious about using old and new variables without using for each row on the creation of the trigger. Is this possible?
    Or maybe I can score some variables static for this query (so sysdate will be the same and some of the Pavilion for the insertion of small newspapers)?
    Or maybe is there other ways to do it?

    LeopoldStoch wrote:
    But if I use sysdate in each trigger and it will update something as my sysdate 100000 lines will be different for different lines but I want it to be time and on the same date.

    Hi Leopold,

    Then today is your lucky day :-): sysdate is the same for all the DML. Even if it takes more than one second:

    SQL> create table rob
      2  ( id int
      3  , creation_date date
      4  )
      5  /
    
    Table created.
    
    SQL> create trigger t
      2  before insert on rob
      3  for each row
      4  begin
      5          :new.creation_date := sysdate;
      6  end;
      7  /
    
    Trigger created.
    
    SQL> set timing on
    SQL> insert into rob (id)
      2   select level
      3     from dual
      4  connect by level <= 10000
      5  /
    
    10000 rows created.
    
    Elapsed: 00:00:00.37
    SQL> set timing off
    SQL> select min(creation_date)
      2       , max(creation_date)
      3    from rob
      4  /
    
    MIN(CREATION_DATE)  MAX(CREATION_DATE)
    ------------------- -------------------
    07-05-2010 09:29:24 07-05-2010 09:29:24
    
    1 row selected.
    

    You can read more here: http://rwijk.blogspot.com/2008/07/sysdate.html

    Kind regards
    Rob.

  • The quotes appear automatically at the end of each line

    Normal return at the end of a line of text create quote marks, shift return has not, anyone know of a way to stop this? Located mainly on older presentations which were brought in more recent versions of Keynote. It doesn't seem to be a problem of quote auto that nothing appears at the beginning of each line.

    Never heard of this issue. Try the following:

    1. open a new presentation and then drag and drop the original in the new slides,

    2 - Copy and paste the text of the original in a new text box in a new presentation.

  • Is there a way to stop the Mail to save each line of an email I write separately in the trash?

    Is there a way to stop the Mail to save each line of an e-mail message that I write and save it as a draft in the trash? It is a new behavior since I updated to El Capitan, and I can't find anything about this in the preferences or help.

    Hmm.  This seems odd.

    Specify it as an IMAP account.

    Check your MailPreferences behavior forMailBox > drafts

  • can see us line numbers next to each step in the sequence file?

    Hello

    I have a file of sequence having 600 steps. I would like to know is there any option to the test to set number for each step in the sequence of line editor so that it is useful for the review.

    Example:

    1 Action1

    2 Action2

    ............

    600 Action600

    Kind regards

    Krishna

    Krishna,

    If you want just to know the index of a step, this information is displayed at the bottom of the sequence editor in the status bar.  It shows you how many steps there are in the sequence, how you have selected and the index of the selected steps.

    It is also possible to display the information in the view of the steps in a column, if you are ready to create a new column.  Follow the instructions in this KB to see how to create a new column:changing the properties of columns in the viewport of execution TestStand sequence editor.

    One of the types of columns is Index. Just set your column of this type and you'll see step index as shown below.

  • How many fields have horizontally with a label at the beginning of each line

    jdev12c

    I'm trying to implement search criteria screen myself.

    When I select a lookup field in a drop-down list, this field is added to the screen. It has a label, a text field and a selectOneChoice of the operator (with value of begin, end, especially, between the two, etc.).

    When to choose another field of research in the list, a new line is added to the screen.

    I want all tags must be aligned to the right, text boxes are aligned and the selectOneChoice is just after the text box.

    I tried to generate PanelFormLayout for each line, with lines of property = 1 and argument maxcolumns = 3.

    The problem I have with this approach is: labels for each line don't align. Also, I have data recovery problem within each PanelFormLayout. The mother of PanelFormLayouts, he sees several PanelFormLayout. But the returned value of the first PanelFormLayout.

    Please advice what kind of layout that I use. Thank you.

    You can do this using af: panelLabelAndMessage,.

    just surround all your filed with the horizontal band layout and simple true set for all fields, then surround group layout with an element of label and message board

    Source XMl-

    
    
                       
    
                            
    
                            
    
                           
    
                                                        
    
                      
    
                    
    

    It will look like this - https://drive.google.com/file/d/0B0Usl2n1Wz8vUEtPdnVtUC1mcjA/edit?usp=sharing

    See - http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_panelLabelAndMessage.html

    -Ashish

  • Create a line for the new entity using createInstance2 with AttributeList


    I use JDeveloper 11.1.2.3.

    I am creating a method in the Module of the Application to create a new entity row in a child table.

    I think I'm to provide the value of the foreign key for the parent table in the AttributeList argument.

    I have search the Forum and carried out a large number of "Googling", but have not been able to find an example where AttributeList is not null.

    Can you point me to an example?

    Thank you

    I created a method in bean managed to add a line through the iterator for the "join table", passing the primary key for each parent table.

    protected void createHistoryForProblem (String or activity, long fkProbrcptReceiptDtl)
    {
    Get the link for the page container
    BindingContainer bindingContainer = this.getBindingContainerByPath("com_gac_apps_receiving_view_requestConformityPaperworkPageDef");
                                                                           
    DCIteratorBinding dcib = (DCIteratorBinding) bindingContainer.get("AllDetailForAProblemForAReceiptIterator");
       
    RowSetIterator rsi = dcib.getRowSetIterator ();

    Insert a new line
    Line newContactRow = rsi.createRow ();

    disable data validation
    newContactRow.setNewRowState (Row.STATUS_INITIALIZED);

    initialize the columns in the row.
    newContactRow.setAttribute ("FkProbrcptReceiptDtl", fkProbrcptReceiptDtl);
       
    newContactRow.setAttribute ("FkProbrcptReceiptActvy", 2);
      
    Insert the new line
    rsi.insertRow (newContactRow);
    rsi.setCurrentRow (newContactRow);
       
    OperationBinding operationBinding = bindingContainer.getOperationBinding ("Commit");

    Object result = operationBinding.execute ();
    If (! operationBinding.getErrors () .isEmpty ())
    {
    StringBuffer sb = new StringBuffer();
         
    List errors = operationBinding.getErrors ();
         
    for (object error: errors)
    {
    SB. Append (error + "/ n");
    }
         
    throw new RuntimeException ("error occurred during the Commission of the data in createHistoryForProblem-" + sb.toString ());
    }
    }

  • How to create the new line in actionscript 3

    I have this simple script that is supposed to take a comma to separate values from xml and transform into something similar to an unordered list if only I could get a '\n' to work. Here is my script.

    var dont_forget:Array = myXML... dont_forget [n]. Split(",");

    var d: Number = dont_forget.length;

    While (d-) {}

    detailsMovieClip_mc.dont_forget.text = ">" + dont_forget [i] + "\n\r";

    trace (dont_forget [d]);

    }

    When the trace is running it shows me the values so I know they are there. However, I see that the last value. How to create a new line as a 3?

    Use the appendText method.  By assigning the text using "=" you're crushing on each pass through the loop.

    detailsMovieClip_mc.dont_forget.appendText (' > '+ dont_forget [d] + "\n\r" ');

  • Links out to the new line?

    I am currently working on a new site based on CSS on a test server.

    I came up against a problem that makes no sense. Links included in the text to other pages or the destinations which have a CSS hover effect sometimes appear on a single line (correct), but at other times the line of text break on the following line when either before I hover over the link or after. This then breaks the flow of the page instead of the background color showing just behind the link. because of the lines of fracture to the other line shows effect hover on the full range?

    It is not systematically; It comes and goes; I don't see where it comes from; two lines that contain links will appear exactly the same in construction, but react differently with the mouse?

    Any help with this problem would be greatly appreciated. 2 links behave differently on the same page?

    > [b} #column a: link, a: visited {I thought would cover the rules]
    > for
    > the right column.

    Not quite.

    This is known as grouping the descendant selectors in a list separated by commas.

    However, each item in the list (between commas) is treated independently.

    "#column a: link, a: visited" is the same as #column a: link {;} rules more
    a: visited {rules ;}

    After the comma, he must again specify the id selector "#column" then
    Display: block applies only to one: went inside the '#column '.

    In other words, "#column a: link, a: visited" should be "#column a: link,
    "#column a: visited.

    As it is written currently, all States visited the tag is set to
    Display: block, which causes the break on lines after having clicked on everything
    link in the body of the text.

    --
    Concerning

    John Waller

  • How to get only the new lines

    Hello

    I have a table as below

    emp_id (integer)
    id_est (integer)
    dt_est (date)

    for each emp_id I have several id_est with several dt_est... as below

    emp_id id_est dt_est
    1 1 10-01 - 2009
    1 2 2009 - 01 - 13
    2 3 2009 - 01 - 10
    2 4 2009 - 01 - 12
    2 5 2009 - 01 - 14
    3 6 2009 - 01 - 12
    4 7 2009 - 01 - 15
    5 8 2009 - 01 - 17
    5 9 2009 - 01 - 19

    I would get just the news lines function date each emp_id, so my result should be as below

    emp_id id_est dt_est
    1 2 2009 - 01 - 13
    2 5 2009 - 01 - 14
    3 6 2009 - 01 - 12
    4 7 2009 - 01 - 15
    5 9 2009 - 01 - 19

    How I do that?

    Thank you

    Hello

    Try this code.

    Salim cordially.

    SELECT   id_emp, MAX (id_est), MAX (dt_est)
        FROM t
    GROUP BY id_emp
    
  • After the installation of update ver14.0.1, when you print a page on aweb site, why is that each line of the page to be printed each line on a separate page? !

    Each line in the document is printed on a separate page, IE: ten lines will print 10 separate pages for printing.

    Try of the reset described here:

    http://KB.mozillazine.org/Problems_printing_web_pages#Reset_printer

    Make sure that you reset all the print preferences.

Maybe you are looking for