Max returns two rows

select BOND_SCHED_ID,bond_id,earnings_proceeds,max(s.effective_date) as effective_date
from XXDL.xxdl_cd_bond_schedk_p2b  s
Group by BOND_SCHED_ID,bond_id,earnings_proceeds
Table has two rows it returns two rows. I need to have a single folder
Actual

10020     7     200     01-FEB-11
10000     7     100     01-JAN-11

Expected
10020     7     200     01-FEB-11
What is the best application I can write

893185 wrote:

Table has two rows it returns two rows. I need to have a single folder

According to what criteria? I'll assume last effective_date for the connection id. If so:

select  bond_sched_id,
        bond_id,
        effective_date
  from  (
         select  s.*,
                 row_number() over(partition by bond_id order by effective_date desc) rn
           from  XXDL.xxdl_cd_bond_schedk_p2b s
        )
  where rn = 1
/

SY.

Tags: Database

Similar Questions

  • two rows of back with a single column with just one place

    Hello all;
    I have a query that returns two rows similar to this below
    
    ID      PLACE            PROGRAM
    A       NEWYORK      PROGRAM A
    A       NEWYORK      PROGRAM B
    
    I would like this instead
    
    ID      PLACE             PROGRAM
    A       NEWYORK       PROGRAM A
                                   PROGRAM  B
    
    All help is appreciated. Thank you.
    Published by: user13328581 on March 22, 2011 11:52

    user13328581 wrote:
    WOW... Thanks a lot for Salomon, I never used the partitions and row_number in such a way... can you please explain your logic.

    Ensure that:

    ROW_NUMBER() over (partition by order of identification by location, program)

    This operation can take all the rows returned by the query andsplit them in compartments (sheet music) by id. Inside each bucket it order lines by program and place and assign line numbers. So for each row of the ID number 1 will be stored with (in alphabetical order) first place the first programt. And this is the line where we want to ID is displayed. That's why we wrap the analytical function that precedes in the CASE statement that will do just that. Now:

    ROW_NUMBER() over (partition by id, order by program)

    pretty much the same just bucket is a combination ID / PLACE. So for each combination of it, we want to show that for the first (in alphabetical order) programt.

    Now notice in the ORDER BY clause I prefix ID and PLACE with the table alias. You do it because otherwise the query alias ID and PLACE will have priority resulting in the incorrect sort order (remember that we cancelled all ID and PLACE with the exception of the number of line 1).

    SY.

  • during the partition: how to use to return the max of two columns

    Each unique id, I want to select the col2 value in the folder with the most recent date.
    When the lines with the same IDS have the same dates, I select the max value of col2.
    I want a line for each ID, but I get two rows for ID 3333333.

    with the data as
    (
    Select 1111111 as id, 'a' as col2, to_date('01-JAN-09','dd-mon-yyyy') like double union all the_date
    Select 2222222 as id, 'b' as col2, to_date('02-JAN-09','dd-mon-yyyy') like double union all the_date
    Select 2222222 as id, 'c' as col2, to_date('03-JAN-09','dd-mon-yyyy') like double union all the_date
    Select 2222222 as id, would be "like col2, to_date('04-JAN-09','dd-mon-yyyy') as the_date of all the double union"
    Select 3333333 as id, 'e' as col2, to_date('05-JAN-09','dd-mon-yyyy') like double union all the_date
    Select 3333333 as id, 'f' as col2, to_date('05-JAN-09','dd-mon-yyyy') like double the_date
    )
    SELECT id, col2, the_date
    Of
    (
    SELECT id, the_date, max (the_date) or col2 in (score by id) as max_the_date, max (col2) over (partition of col2) as max_col2
    from the data
    )
    where the_date = max_the_date and col2 = order by id max_col2


    Expecting this:
    COL2 ID THE_DATE
    1111111 a 01/01/09
    2222222 d 04/01/09
    3333333 f 05/01/09

    but I get 2 rows for ID 3333333

    Any suggestions?

    Use row_number(), not the max() to compare.

    with data as
    (
    select 1111111 as id, 'a' as col2, to_date('01-JAN-09','dd-mon-yyyy') as the_date from dual union all
    select 2222222 as id, 'b' as col2, to_date('02-JAN-09','dd-mon-yyyy') as the_date from dual union all
    select 2222222 as id, 'c' as col2, to_date('03-JAN-09','dd-mon-yyyy') as the_date from dual union all
    select 2222222 as id, 'd' as col2, to_date('04-JAN-09','dd-mon-yyyy') as the_date from dual union all
    select 3333333 as id, 'e' as col2, to_date('05-JAN-09','dd-mon-yyyy') as the_date from dual union all
    select 3333333 as id, 'f' as col2, to_date('05-JAN-09','dd-mon-yyyy') as the_date from dual
    )
    select id, col2, the_date
    from (select id,
                 the_date,
                 col2,
                 row_number() over (partition by id order by the_date desc, col2 desc) r
          from data)
    where r = 1;
    
    ID                     COL2 THE_DATE
    ---------------------- ---- -------------------------
    1111111                a    01-JAN-09
    2222222                d    04-JAN-09
    3333333                f    05-JAN-09                 
    
    3 rows selected
    

    Published by: tk-7381344 on March 5, 2009 11:46

  • Min and Max in a row!

    Hi guys,.

    Do you know how I can get the MIN and MAX in a row?

    For example:

    C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8

    10. 50. 70.  5. 90. 135. 4   | 60

    I return 4 and 135.

    I can return it without using the service?

    Thank you

    Eric

    create table t as
    with d as (
      select 1 n from dual
      union all
      select null from dual
    )
    select a.n c1, b.n*2 c2, c.n*3 c3
    from d a, d b, d c;
    
    select c1,c2,c3,
    greatest(
      coalesce(c1,c2,c3),
      coalesce(c2,c3,c1),
      coalesce(c3,c1,c2)
    ) greatest_c,
    least(
      coalesce(c1,c2,c3),
      coalesce(c2,c3,c1),
      coalesce(c3,c1,c2)
    ) least_c
    from t;
    
    C1 C2 C3 GREATEST_C LEAST_C
    1 2 3 3 1
    1 2 2 1
    1 3 3 1
    1 1 1
    2 3 3 2
    2 2 2
    3 3 3
  • Stupid old backpacker (me) cannot understand why this query returns 1 row

    Hi all

    In reference to {: identifier of the thread = 2456973}, why do
    select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
    , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
    from emp group by job;
    only 1 rank and not 1 for each task? In fact, I had to test it myself to believe.

    It returns the data as if the query were
    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)
    Using only a single aggregate (count or sum) returns 1 row per job, as expected

    John Stegeman wrote:
    It returns the data as if the query were

    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
    from emp group by job)
    

    Exactly the point ;-)

    It seems that Oracle actually do, a group of 'double' in the same operation.
    Attend plans to explain in this example:

    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3  from scott.emp group by job;
    
        CLERKS  SALESMANS
    ---------- ----------
             0          0
             0          0
             0          0
             0          4
             4          0
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1697595674
    
    ---------------------------------------------------------------------------
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  HASH GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------
    

    And compare it to the one with the double aggregates:

    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3  from scott.emp group by job;
    
        CLERKS  SALESMANS
    ---------- ----------
             4          4
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 417468012
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    There are GROUP BY hash and SORT GLOBAL times.

    It is really unnecessary to an aggregate on an aggregate - if two aggregates are used "in the same group level.
    Sum() aggregates are used on an already aggregated value, so it doesn't look like Oracle which actually cures like 'first do the internal aggregate using the group specified by and then do the external aggregation on the result with any group.'

    Look at this example where I combine aggregates "double" with "single" aggregates:

    SQL> select sum(count(decode(job, 'CLERK', 1, null))) CLERKS
      2       , sum(count(decode(job, 'SALESMAN', 1, null))) SALESMANS
      3       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS2
      4       , count(*) COUNTS
      5  from scott.emp group by job;
    
        CLERKS  SALESMANS SALESMANS2     COUNTS
    ---------- ---------- ---------- ----------
             4          4          1          5
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 417468012
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   2 |   HASH GROUP BY     |      |     1 |     8 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    When you mix "doubles" and "single" aggregates, Oracle decides that unique aggregates belong to the 'outer' aggregation
    SALESMAN2 did a count on the aggregated work column which is the result of the 'internal' group by - so only 1.
    The count (*) is also the result of the aggregation of the 'internal '.

    I don't know if it's documented or if it is an 'effect' of internal code used for GROUPING SETS or the internal code used to enable the analytical functions like this:

    SQL> select count(decode(job, 'CLERK', 1, null)) CLERKS
      2       , count(decode(job, 'SALESMAN', 1, null)) SALESMANS
      3       , sum(count(decode(job, 'CLERK', 1, null))) over () CLERKS2
      4       , sum(count(decode(job, 'SALESMAN', 1, null))) over () SALESMANS2
      5  from scott.emp group by job;
    
        CLERKS  SALESMANS    CLERKS2 SALESMANS2
    ---------- ---------- ---------- ----------
             0          0          4          4
             4          0          4          4
             0          0          4          4
             0          0          4          4
             0          4          4          4
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 4115955660
    
    ----------------------------------------------------------------------------
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT    |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   1 |  WINDOW BUFFER      |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   2 |   SORT GROUP BY     |      |     5 |    40 |     4  (25)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| EMP  |    14 |   112 |     3   (0)| 00:00:01 |
    ----------------------------------------------------------------------------
    

    Personally, I think that I would have preferred if Oracle has raised an error on this "double aggregation" and therefore require me to write this way (if it's the result I wanted):

    select sum(CLERKS), sum(SALESMANS)
    from (select count(decode(job, 'CLERK', 1, null)) CLERKS, count(decode(job, 'SALESMAN', 1, null)) SALESMANS
             from emp group by job)
    

    I don't really see a good use case for aggregations of 'double'-, but rather that he could give you undetected bugs in your code, if you happen to do double aggregation without noticing.

    Interesting thing to know ;-)

  • Fetch returns multiple rows

    Hello
    I have the following table:
    ID number, not null, unique
    fname varchar2(50),not null
    lname varchar2(50), not null
    email varchar2(200)not null, unique
    and the following procedure that queries the table:
    declare
    name varchar2(100);
    email varchar2(500);
    stmt varchar2(4000);
    nbr number;
    begin
    name:=substr('sam wilkins:[email protected]',1,(instr('sam wilkins:[email protected]',':')-1));
    email:=substr('sam wilkins:[email protected]',(instr('sam wilkins:[email protected]',':')+1));
    stmt:='select id from tbl where '
          || 'fname ||'' ''||'
          || 'lname='|| ''''||lower(name)||''''||' and email='||''''||lower(email)||''''||'';
    execute immediate stmt into nbr;
    select id into nbr from tbl where fname||' '||lname = name and email = email;
    dbms_output.put_line(stmt);
    dbms_output.put_line(nbr);
    end;
    When I run the procedure with just the immediate execution, the query returns a single id, but when I use select it in, I get the error "Fetch returns more rows". Why is this?

    Thank you.

    Hello

    natet wrote:
    Hello
    I have the following table:

    ID number, not null, unique
    fname varchar2(50),not null
    lname varchar2(50), not null
    email varchar2(200)not null, unique
    

    and the following procedure that queries the table:

    declare
    name varchar2(100);
    email varchar2(500);
    stmt varchar2(4000);
    nbr number;
    begin
    name:=substr('sam wilkins:[email protected]',1,(instr('sam wilkins:[email protected]',':')-1));
    email:=substr('sam wilkins:[email protected]',(instr('sam wilkins:[email protected]',':')+1));
    stmt:='select id from tbl where '
    || 'fname ||'' ''||'
    || 'lname='|| ''''||lower(name)||''''||' and email='||''''||lower(email)||''''||'';
    execute immediate stmt into nbr;
    select id into nbr from tbl where fname||' '||lname = name and email = email;
    dbms_output.put_line(stmt);
    dbms_output.put_line(nbr);
    end;
    

    When I run the procedure with just the immediate execution, the query returns a single id, but when I use select it in, I get the error "Fetch returns more rows". Why is this?

    Thank you.

    Give your local variable names that can be confused for column names.

    In this statement:

    select  id
    into      nbr
    from      tbl
    where      fname ||' '|| lname     = name
    and      email                      = email;
    

    e-mail (in two places) refers to the column in the table. Probably, you want to use the local variable in place of one of them.

  • Update returns multiple rows

    Basically, I have two tables:

    We have CUS_NO, AS_OF_DATE, AVG_AMT, CLOSING_BALANCE and DATE_JOINED
    In this table, AVG_AMT is empty

    Second table has CUS_NO, AS_OF_DATE and AVG_AMT

    The average amt can be + ve - ve or both.

    I do an update like this:

    Update table1 set AVG_AMT = (select AVG_AMT from table2 where table1. CUS_NO = table2. CUS_NO)

    With this, I get the error "single subquery returns more rows" which is just, because some customers have two EV - and + ve AVG_AMT

    How would you advise me to tackle this problem?
    For example: If Table1
    CUS_NO DATE_JOINED CLOSING_BALANCE AS_OF_DATE AVG_AMT
    123 10/10/09 12345 10/10/09 < NULL >

    and the table2

    CUS_NO AS_OF_DATE AVG_AMT
    123 10/10/09 2000
    123-10/10/09-400


    The end result should be

    CUS_NO DATE_JOINED CLOSING_BALANCE AS_OF_DATE AVG_AMT
    123 10/10/09 12345 10 / 10 / 0 2000
    123 10/10/09 12345 10/10/09-400

    Double Post.

    Kind regards.

    LOULOU.

    Published by: Satyaki_De on November 19, 2009 17:35

  • How can I move App Tabs down, where are the other bookmark toolbars? Or, how can I put my toolbars on two rows bookmarks and forget the App Tabs?

    I have several bookmarks in my toolbar, and my most often used found in a drop down menu, which is annoying. I have tried to click and drag on the menu bar, there was room for more icons, but they didn't budge. Anything under the "toolbar" has been helpful. Help tell me do right click on my toolbar and then click on 'Customize'... which did not come as an option. I would like to really all my favorites toolbar (I have about 10) or real on the toolbar visible, not hidden in a small dropdown tab menu.
    There is a plug-in that allows you to put bookmarks in two rows on your toolbars, but it is not compatible with my version of FF (7.0.1).
    App Tabs are cute, but I don't like them on top where they take place where I have the legs for various open websites (I usually opened several at once). App Tabs are fixed and do not move as site tabs, which is extremely annoying and so why I 1) want to move to the bottom of the toolbar or 2) be able to view all my bookmarks toolbars - which is what I prefer.
    BTW, I have Windows 7.
    Thanks in advance for your help.

    App tabs are special tablets and are always displayed at the left end of the tab bar.

    You can place all the bookmarks that you want to see the toolbar of bookmarks in the bookmarks toolbar folder.

    You can do this in the sidebar or the Manager of bookmarks if you can't do it on the bookmarks toolbar.

    Most visited is a special file (smart) which shows the websites that you have visited and are not necessarily Favorites, so you can not drag on the personal bar unless you first to bookmark the. You can make it open in a tab by clicking on Star on location bar twice and choose the toolbar of bookmarks as destination folder.

  • HP Laserjet P1102: Two rows of black dots on every print

    I recently removed the seals and tested a few impressions, but each of them contains two rows of black dots on the left side (a line more fat and other points more small rank). I did the cleaning print but no use. Here are some pictures of the question. I can print any document, but the points are the problem. I run on the genuine laser HP cartridge by default. Also, the points are spaced the same way.  Any help would be appreciated...

    No! The load inside the cartridge is bad

  • Mr President, how can I enter two rows at the same time with different default values that only the first line to use see?

    Mr President.

    My worm jdev is 12.2.1

    How to enter two rows at the same time with different default values that only the first line to use see?

    Suppose I have a table with four fields as below

    "DEBIT" VARCHAR2(7) , 
      "DRNAME" VARCHAR2(50),
      "CREDIT" VARCHAR2(7) , 
      "CRNAME" VARCHAR2(50),
    

    Now I want that when I click on a button (create an insert) to create the first line with the default values below

    firstrow.png

    So if I click on the button and then validate the second row with different values is also inserted on commit.

    The value of the second row are like the picture below

    tworows.png

    But the second row should be invisible. It could be achieved by adding vc in the vo.

    The difficult part in my question is therefore, to add the second row with the new default values.

    Because I already added default values in the first row.

    Now how to add second time default values.

    Concerning

    Mr President

    I change the code given by expensive Sameh Nassar and get my results.

    Thanks once again dear Sameh Nassar .

    My code to get my goal is

    First line of code is

        protected void doDML(int operation, TransactionEvent e) {    
    
            if(operation != DML_DELETE)
                 {
                     setAmount(getPurqty().multiply(getUnitpurprice()));
                 } 
    
            if (operation == DML_INSERT )
                       {
                               System.out.println("I am in Insert with vid= " + getVid());
                           insertSecondRowInDatabase(getVid(),getLineitem(),"6010010","SALES TAX PAYABLE",
                            (getPurqty().multiply(getUnitpurprice()).multiply(getStaxrate())).divide(100));      
    
                           }
    
            if(operation == DML_UPDATE)
                              {                                                    
    
                                 System.out.println("I am in Update with vid= " + getVid());
                             updateSecondRowInDatabase(getVid(),
                                 (getPurqty().multiply(getUnitpurprice()).multiply(getStaxrate())).divide(100));      
    
                              }                      
    
            super.doDML(operation, e);
        }
        private void insertSecondRowInDatabase(Object value1, Object value2, Object value3, Object value4, Object value5)
                  {
                    PreparedStatement stat = null;
                    try
                    {
                      String sql = "Insert into vdet (VID,LINEITEM,DEBIT,DRNAME,AMOUNT) values " +
                 "('" + value1 + "','" + value2 + "','" + value3 + "','" + value4 + "','" + value5 + "')";  
    
                      stat = getDBTransaction().createPreparedStatement(sql, 1);
                      stat.executeUpdate();
                    }
                    catch (Exception e)
                    {
                      e.printStackTrace();
                    }
                    finally
                    {
                      try
                      {
                        stat.close();
                      }
                      catch (Exception e)
                      {
                        e.printStackTrace();
                      }
                    }
                  }  
    
                  private void updateSecondRowInDatabase(Object value1, Object value5)
                  {
                    PreparedStatement stat = null;
                    try
                    {
                      String sql = "update vdet set  AMOUNT='"+ value5+"' where VID='" + value1 + "'";                     
    
                      stat = getDBTransaction().createPreparedStatement(sql, 1);  
    
                      stat.executeUpdate();
                    }
                    catch (Exception e)
                    {
                      e.printStackTrace();
                    }
                    finally
                    {
                      try
                      {
                        stat.close();
                      }
                      catch (Exception e)
                      {
                        e.printStackTrace();
                      }
                    }                  
    
                  }
    

    Second line code is inside a bean method

        public void addNewPurchaseVoucher(ActionEvent actionEvent) {
            // Add event code here...
    
            BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
                   DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("VoucherView1Iterator");
                   RowSetIterator rsi = dciter.getRowSetIterator();
                   Row lastRow = rsi.last();
                   int lastRowIndex = rsi.getRangeIndexOf(lastRow);
                   Row newRow = rsi.createRow();
                   newRow.setNewRowState(Row.STATUS_NEW);
                   rsi.insertRowAtRangeIndex(lastRowIndex +1, newRow);
                   rsi.setCurrentRow(newRow);
    
                   BindingContainer bindings1 = BindingContext.getCurrent().getCurrentBindingsEntry();
                   DCIteratorBinding dciter1 = (DCIteratorBinding) bindings1.get("VdetView1Iterator");
                   RowSetIterator rsi1 = dciter1.getRowSetIterator();
                   Row lastRow1 = rsi1.last();
                   int lastRowIndex1 = rsi1.getRangeIndexOf(lastRow1);
                   Row newRow1 = rsi1.createRow();
                   newRow1.setNewRowState(Row.STATUS_NEW);
                   rsi1.insertRowAtRangeIndex(lastRowIndex1 +1, newRow1);
                   rsi1.setCurrentRow(newRow1);
        }
    

    And final saveUpdate method is

        public void saveUpdateButton(ActionEvent actionEvent) {
            // Add event code here...
    
            BindingContainer bindingsBC = BindingContext.getCurrent().getCurrentBindingsEntry();      
    
                   OperationBinding commit = bindingsBC.getOperationBinding("Commit");
                   commit.execute(); 
    
            OperationBinding operationBinding = BindingContext.getCurrent().getCurrentBindingsEntry().getOperationBinding("Commit");
            operationBinding.execute();
            DCIteratorBinding iter = (DCIteratorBinding) BindingContext.getCurrent().getCurrentBindingsEntry().get("VdetView1Iterator");// write iterator name from pageDef.
            iter.getViewObject().executeQuery();  
    
        }
    

    Thanks for all the cooperation to obtain the desired results.

    Concerning

  • subquery returns no row in the main query, but hard returns the value of the master query

    Oracle 11g, Solaris SPARC 64-bit:

    This is the master query: its not to return all the lines

    Select count (*) in the sadmin.usr_mods where to_char (ts_id) in ((select to_char (rtrim (ltrim(TS_MODULES,','), ',')) in the sadmin.usr_rfc where TS_KINTANA_PACKAGE_NUMBER = '123' and ts_projectid = 3));

    COUNT (*)

    ----------

    0

    But wherever if I use subquery only returns he lines:

    SQL > select rtrim (ltrim(TS_MODULES,','), ',') from the sadmin.usr_rfc where TS_KINTANA_PACKAGE_NUMBER = '123' and ts_projectid = 3;

    RTRIM (LTRIM(TS_MODULES,','), ',')

    --------------------------------------------------------------------------------

    49,54

    If I use these values as hardcoded to a select master it will return 2 rows:

    SQL > select count (*) in the sadmin.usr_mods where to_char (ts_id) in ('49 ', ' 54');

    COUNT (*)

    ----------

    2

    TS_MODULES datatype is CLOB

    TS_ID datatype is set to number

    Help, please

    with

    usr_rfc as

    (select 3 ts_projectid, 123 ts_kintana_package_number, to_clob(',49,54,') ts_modules

    of the double

    ),

    usr_mods as

    (select ts_id 49 Union double all the)

    Select 50 in all double union

    Select double 54

    )

    Select count (*)

    of usr_mods

    where to_char (ts_id) in (select regexp_substr (to_char (rtrim (ltrim(TS_MODULES,','), ',')),'[^,] +', 1, level))

    of usr_rfc

    where TS_KINTANA_PACKAGE_NUMBER = '123'

    and ts_projectid = 3

    connect by level<= regexp_count(to_char(rtrim(ltrim(ts_modules,','),',')),',')="" +="">

    )

    COUNT (*)
    2

    Concerning

    Etbin

    Select count (*)

    of usr_mods

    where instr ((select ',' | to_char (rtrim (ltrim(TS_MODULES,','), ',')) |)) ','

    of usr_rfc

    where TS_KINTANA_PACKAGE_NUMBER = '123'

    and ts_projectid = 3

    ),

    ',' || TO_CHAR (TS_ID) | ','

    ) > 0

  • Concatenate two rows

    Hello

    I have a requirement where to check a table with a list of values in reference data.

    I get two rows with a column for each output that every time and I need to concatenate the two rows in a field.

    Is there any combination/processor that can be used to do this?

    I tried concatenate / merge and merge data from processors without success.

    Any direction is much appreciated.

    Thank you

    SID

    It is not clear what criteria do you use to determine which records to eat together. The research is not relevant?

    If it's all the records that spent searching you need to eat, it's simple, you can just add a grouping key (for example to add string to a value of 1 attribute), and then group and merge, creating a merged with output value ' delimited list by a "which is used to create the string.

  • Difference between two rows in a table.

    Hi all

    I have a requirement where I need to calculate the difference of a column, but the values are in two rows.

    Its exactly like that, I'll have a table where I have stored incidents with their status and their modification dates

    example:
    Incident_Id: Status: Modified_Date (in seconds from a specific date)
    1: 1: 9080890
    1: 2: 9080999
    1: 3: 9081900
    2: 1: 10000900
    2: 2: 10001000
    2: 3: 10002000

    Now there I show the time spent by each incident in each State.

    That is to say for the State 1 I need the difference between the date of change of condition 2 and updated the date of status 1 Similarly

    2 necessary status the difference between the date of change of condition 3 and updated the status date 2 and so on.

    the real result, I need is like that

    Incident_Id: Status: Timespent
    1: 1: (modified_date (status2) - modified_date (status1))


    Please help me to write the query to do this.

    Kind regards
    Tauceef

    Can we assume that the lines are classified according TO the event status ?
    This (i.e. an Ordering) is necessary in order to systematically identify consecutive lines.

    Please try the analytical function LAG and less to the current value.

  • Remove ' / ' with a value of feld to create two rows

    I have a table with a structure like

    CREATE TABLE TEST
    (
    MOLDCODE VARCHAR2 (20 BYTE) NOT NULL ACTIVATE.
    PRODCODE VARCHAR2 (255 BYTE),
    DIAMCONTAINER NUMBER (4.1).
    SEGMENT NUMBER (2.0)
    )

    And it contains data such as

    MOLDCODE PRODCODE DIAMCONTAINER SEGMENT

    ADE16920-1 CJ02A/SD51A 96 10
    ADE20206 CT25A 95 8
    ADE16912-1 DG31A 57 10
    ADE16913 AS30A/DE28A 96 10
    ADE17845 CJ24A/SD36A 96 10


    I want to create another table saw which will remove / of prodcode and he will separate the values and forms two rows with the same values for the other fields.
    for example.

    Source: -.
    MOLDCODE PRODCODE DIAMCONTAINER SEGMENT

    ADE16920-1 CJ02A/SD51A 96 10
    ADE16913 AS30A/DE28A 96 10

    Purpose: -.
    MOLDCODE PRODCODE DIAMCONTAINER SEGMENT

    ADE16920-1 96 10 CJ02A
    ADE16920-1 96 10 SD51A
    ADE16913 AS30A 96 10
    ADE16913 DE28A 96 10

    Is it possible?
    Need help for the same thing.

    Check this box:

        SELECT moldcode,
               REGEXP_SUBSTR (procode,
                              '[^/]+',
                              1,
                              LEVEL)
                  procode,
               diamcontainer,
               segment
          FROM t
    CONNECT BY     LEVEL <= REGEXP_COUNT (procode, '/') + 1
               AND moldcode = PRIOR moldcode
               AND PRIOR SYS_GUID () IS NOT NULL;
    

    See you soon,.
    Manik.

  • single line sub query returns multiple rows

    Hi, please help me to solve this, working with oracle 11g.


    Update t1 set t1.twyindex = twypoly (select twyindex from twyinfo where t1.id = t2.id t2);

    the error message is:
    *
    ERROR on line 1:
    ORA-01427: einreihig subquery returns multiple rows

    Thank you

    don123 wrote:
    Hi paul, thanks...

    duplicate existing due to the business logic data.

    can I use the SQL mentioned above for all cases?

    is it mandatory to remove duplicates?

    Please provide your suggestions...

    If the company says duplicates are allowed, you have to ask the person who wants what, of the different twyindexes, that they want to use
    updating twyinfo table...

    I use the SQL proposed until they tell you that twyindex to use.

Maybe you are looking for