Duplicate values in the union

Hello

I am change the below query, the results that are returned contain duplicates.

For example the 'Customer' column contains the value "GBI-FELIX" 5 times.

I had a glance through the SQL and can not see any because of that. Can you see the problem?

select
to_char(sysdate, 'DD-Mon-YYYY HH24:MI:SS'),
ol.client_id client,
trunc(oh.ship_by_date) shipdate,
nvl(sum(ol.qty_ordered),0) as orig_ord,
nvl(sum(ol.qty_shipped),0) as shipped,
nvl(sum(sm.smpicked),0) as unshipped,
nvl(sum(held.qty_to_move),0) as held,
nvl(sum(rel.qty_to_move),0) as reld,
nvl(sum(mar.qty_to_move),0) as marsh,
sum(ol.qty_ordered - (nvl(ol.qty_tasked,0) + nvl(ol.qty_shipped,0))) - nvl(sum(sm.smpicked),0) as unalloc,
sum(ol.qty_ordered -(nvl(sm.smpicked,0) + nvl(ol.qty_shipped,0))) - nvl(sum(mar.qty_to_move),0) as topick

from    order_line ol,
        order_header oh,
     
        (select sum(qty_picked) as smpicked,
        client_id, order_id, line_id 
        from shipping_manifest
        where shipped != 'Y'
        group by client_id, order_id, line_id) sm,
        
     (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
     where task_type = 'O'
     and status != 'Consol'
     and status!= 'Released'
     and status!= 'In Progress'
     group by task_id, client_id, line_id) held,
        
     (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status != 'Consol'
        and status != 'Hold'
        group by task_id, client_id, line_id) rel,
        
     (select sum(qty_to_move) qty_to_move,
     task_id, client_id, line_id 
        from move_task
     where task_type = 'O'
     and status = 'Consol'
     group by task_id, client_id, line_id) mar
  
where ol.client_id = oh.client_id
and ol.order_id = oh.order_id
and ol.order_id = sm.order_id (+)
and ol.client_id = sm.client_id (+)
and ol.line_id = sm.line_id (+)
and trunc(oh.ship_by_date) = $P{ship_by_date}
and ol.order_id = held.task_id (+)
and ol.client_id = held.client_id (+)
and ol.line_id = held.line_id (+)
and ol.order_id = rel.task_id (+)
and ol.client_id = rel.client_id (+)
and ol.line_id = rel.line_id (+)
and ol.order_id = mar.task_id (+)
and ol.client_id = mar.client_id (+)
and ol.line_id = mar.line_id (+)
and ol.sku_id not in (select sku_id
                  from sku
                  where product_group = 'WIP')
and oh.consignment not like 'DAIRN%'
and oh.client_id != 'DAIRNUNEAT'
group by ol.client_id, ship_by_date

                                         UNION

select
to_char(sysdate, 'DD-Mon-YYYY HH24:MI:SS'),
(select 'Total' from dual) client,
trunc(oh.ship_by_date) shipdate,
nvl(sum(ol.qty_ordered),0) as orig_ord,
nvl(sum(ol.qty_shipped),0) as shipped,
nvl(sum(sm.smpicked),0) as unshipped,
nvl(sum(held.qty_to_move),0) as held,
nvl(sum(rel.qty_to_move),0) as reld,
nvl(sum(mar.qty_to_move),0) as marsh,
sum(ol.qty_ordered - (nvl(ol.qty_tasked,0) + nvl(ol.qty_shipped,0))) - nvl(sum(sm.smpicked),0) as unalloc,
sum(ol.qty_ordered - (nvl(sm.smpicked,0) + nvl(ol.qty_shipped,0))) - nvl(sum(mar.qty_to_move),0) as topick

from    order_line ol,
        order_header oh,
        
        (select sum(qty_picked) as smpicked,
        client_id, order_id, line_id 
        from shipping_manifest
        where shipped != 'Y'
        group by client_id, order_id, line_id) sm,
        
     (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status != 'Consol'
        and status != 'Released'
        and status != 'In Progress'
        group by task_id, client_id, line_id) held,
  
        (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status != 'Consol'
        and status != 'Hold'
        group by task_id, client_id, line_id) rel,
  
        (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status = 'Consol'
        group by task_id, client_id, line_id) mar
  
where ol.client_id = oh.client_id
and ol.order_id = oh.order_id
and ol.order_id = sm.order_id (+)
and ol.client_id = sm.client_id (+)
and ol.line_id = sm.line_id (+)
and ol.order_id = held.task_id (+)
and ol.client_id = held.client_id (+)
and ol.line_id = held.line_id (+)
and ol.order_id = rel.task_id (+)
and ol.client_id = rel.client_id (+)
and ol.line_id = mar.line_id (+)
and ol.order_id = mar.task_id (+)
and ol.client_id = mar.client_id (+)
and ol.line_id = rel.line_id (+)
and ol.sku_id not in (select sku_id
                  from sku
                  where product_group = 'WIP')
and oh.consignment not like 'DAIRN%'
and trunc(oh.ship_by_date) = $P{ship_by_date}
group by ship_by_date

                                               UNION
                                               
select
to_char(sysdate, 'DD-Mon-YYYY HH24:MI:SS'),
(select '1FORZA WIP        ' from dual) client,
trunc(oh.ship_by_date) shipdate,
nvl(sum(ol.qty_ordered),0) as orig_ord,
nvl(sum(ol.qty_shipped),0) as shipped,
nvl(sum(sm.smpicked),0) as unshipped,
nvl(sum(held.qty_to_move),0) as held,
nvl(sum(rel.qty_to_move),0) as reld,
nvl(sum(mar.qty_to_move),0) as marsh,
sum(ol.qty_ordered - (nvl(ol.qty_tasked,0) + nvl(ol.qty_shipped,0))) - nvl(sum(sm.smpicked),0) as unalloc,
sum(ol.qty_ordered - (nvl(sm.smpicked,0) + nvl(ol.qty_shipped,0))) - nvl(sum(mar.qty_to_move),0) as topick

from    order_line ol,
        order_header oh,

        (select sum(qty_picked) as smpicked,
        client_id, order_id, line_id 
        from shipping_manifest
        where shipped != 'Y'
        group by client_id, order_id, line_id) sm,
        
        (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status != 'Consol'
        and status != 'Released'
        and status != 'In Progress'
        group by task_id, client_id, line_id) held,
        
        (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status != 'Consol'
        and status != 'Hold'
        group by task_id, client_id, line_id) rel,
        
        (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status = 'Consol'
        group by task_id, client_id, line_id) mar
        
where ol.client_id = oh.client_id
and ol.order_id = oh.order_id
and ol.order_id = sm.order_id (+)
and ol.client_id = sm.client_id (+)
and ol.line_id = sm.line_id (+)
and ol.order_id = held.task_id (+)
and ol.client_id = held.client_id (+)
and ol.line_id = held.line_id (+)
and ol.order_id = rel.task_id (+)
and ol.client_id = rel.client_id (+)
and ol.line_id = mar.line_id (+)
and ol.order_id = mar.task_id (+)
and ol.client_id = mar.client_id (+)
and ol.line_id = rel.line_id (+)
and trunc(oh.ship_by_date) = $P{ship_by_date}
and ol.sku_id in (select sku_id
                  from sku
                  where product_group = 'WIP')
group by ship_by_date

                                               UNION
                                               
select
to_char(sysdate, 'DD-Mon-YYYY HH24:MI:SS'),
(select 'DAIRNUNEAT' from dual) client,
trunc(oh.ship_by_date) shipdate,
nvl(sum(ol.qty_ordered),0) as orig_ord,
nvl(sum(ol.qty_shipped),0) as shipped,
nvl(sum(sm.smpicked),0) as unshipped,
nvl(sum(held.qty_to_move),0) as held,
nvl(sum(rel.qty_to_move),0) as reld,
nvl(sum(mar.qty_to_move),0) as marsh,
sum(ol.qty_ordered - (nvl(ol.qty_tasked,0) + nvl(ol.qty_shipped,0))) - nvl(sum(sm.smpicked),0) as unalloc,
sum(ol.qty_ordered - (nvl(sm.smpicked,0) + nvl(ol.qty_shipped,0))) - nvl(sum(mar.qty_to_move),0) as topick

from    order_line ol,
        order_header oh,

        (select sum(qty_picked) as smpicked,
        client_id, order_id, line_id 
        from shipping_manifest
        where shipped != 'Y'
        group by client_id, order_id, line_id) sm,
        
        (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status != 'Consol'
        and status != 'Released'
        and status != 'In Progress'
        group by task_id, client_id, line_id) held,
        
        (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status != 'Consol'
        and status != 'Hold'
        group by task_id, client_id, line_id) rel,
        
        (select sum(qty_to_move) qty_to_move,
        task_id, client_id, line_id 
        from move_task
        where task_type = 'O'
        and status = 'Consol'
        group by task_id, client_id, line_id) mar
        
where ol.client_id = oh.client_id
and ol.order_id = oh.order_id
and ol.order_id = sm.order_id (+)
and ol.client_id = sm.client_id (+)
and ol.line_id = sm.line_id (+)
and ol.order_id = held.task_id (+)
and ol.client_id = held.client_id (+)
and ol.line_id = held.line_id (+)
and ol.order_id = rel.task_id (+)
and ol.client_id = rel.client_id (+)
and ol.line_id = mar.line_id (+)
and ol.order_id = mar.task_id (+)
and ol.client_id = mar.client_id (+)
and ol.line_id = rel.line_id (+)
and trunc(oh.ship_by_date) = $P{ship_by_date}
and oh.consignment like 'DAIRN%'
group by ship_by_date
Kind regards

Sam.

What block of union query results in duplicate is the first, 2nd, third or fourth? If you do not try running each query and see if you can find them.

Tags: Database

Similar Questions

  • How to find duplicates of a field value? For example - in a field, I have values like {123,345,346,123}, now I want to remove the duplicate value in the field so that my output looks like {123,345,346}

    How to find duplicates of a field value? For example - in a field, I have values like {123,345,346,123}, now I want to remove the duplicate value in the field so that my output looks like {123,345,346}

    If it's an array you want to deduplicate then here is a script [for use in the Script Processor] I prepared earlier:

    var result = new Array();

    var added = new Object();

    If (input1 [0]! = null)

    {

    for (var i = 0; i)< input1[0].length;="">

    {

    var point = input1 [0] [i];

    If (! added [item])

    {

    added [item] = 1;

    result [result. Length] = item;

    }

    }

    }

    Output 1 = result;

    Kind regards

    Nick

  • Check all the duplicate values in the column COUNT()

    Hello

    I'll do some tests, and for this I need to retrieve data based on a single column for example test_data_col, which-
    1 to 3 or more count (test_data_col) for a given set of columns for example grp_col1, grp_col2, grp_col3 group
    2. overall recovered lines, this particular column has some duplicate values. I don't need displayed duplicates, just whether or not duplicates exist.

    Which could explain what I'm trying to do -

    grp_col1, grp_col2, grp_col3, test_data_col

    1, A, xyz, HELLO
    1, A, xyz, HELLO
    1, a, xyz, BYE
    1, A, xyz, goodbye

    2, C, pqr, WELCOME
    2, C, pqr, GOOD MORNING
    2, C, pqr, BAD MORNING

    So for condition 1, I do something like that.
    SELECT COUNT(test_data_col) cnt, grp_col_1, grp_col2, grp_col3
    FROM test_tab
    GROUP BY grp_col_1, grp_col2, grp_col3
    HAVING COUNT(test_data_col) >= 3;
    In this request, I want to do something that will tell me if the aggregate COUNT (test_data_col) has all the duplicate values it contains. Yet once, display the duplicates is not important here.
    SELECT COUNT(test_data_col) cnt, grp_col_1, grp_col2, grp_col3,
    /*some logic*/ dup_val
    FROM test_tab
    GROUP BY grp_col_1, grp_col2, grp_col3
    HAVING COUNT(test_data_col) >= 3;
    With the correct to replace coding / * some * logic /, I have following values.

    CNT, grp_col_1, grp_col2, grp_col3, dup_val

    4, 1, a, xyz, Y
    3, 2, C, pqr, N

    I have dup_val column to explain what I'm trying to achieve... Another way to know the existence of duplicates in the aggregate count will be fine.

    My version of Oracle's Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0

    Do you like the answer!

    Your somewhere logical can be like that

    case when COUNT(test_data_col) != COUNT(distinct test_data_col) the 'Y' else 'N' end dup_val
    
  • Values in the list by the order of table in SELECT Union

    Version: 11.2

    Apparently a very basic thing. But I couldn't do it :)

    In the UNION example below automatic sorting in is based on alphabetical order. I want to get rid of this sort and list the values according to the order of the table in the SELECT.

    Test data
    create table test1 (name1 varchar2(10));
    
    create table test2 (name2 varchar2(10));
    
    create table test3 (name3 varchar2(10));
    
    
    insert into test1 values ('EARTH');
    insert into test1 values ('TAURUS');
    insert into test2 values ('YELLOW');
    
    insert into test2 values ('ALPHA');
    insert into test2 values ('TANGO');
    
    
    insert into test3 values ('BRAVO');
    
    
    select name1 from test1
    union
    select name2 from test2
    union
    select name3 from test3;
    
    NAME1
    ----------
    ALPHA
    BRAVO
    EARTH
    TANGO
    TAURUS
    YELLOW
    
    6 rows selected.
    In the above example, I want the values in the first array SELECT listed first, then all the values of the second table in SELECT it and so on.

    Basically my requirement will be
    Return all values from test1 (alphabetically sorted)
    then
    Return all values from test2 (alphabetically sorted)
    then
    Return all values from test3 (alphabetically sorted)
    Expected results:
    NAME1
    ----------
    EARTH  ------------> from the first table in the SELECT
    TAURUS ------------> from the first table in the SELECT
    ALPHA  ----------------------> from the second table in the SELECT
    TANGO  ----------------------> from the second table in the SELECT
    YELLOW ----------------------> from the second table in the SELECT
    BRAVO  ------------------------------> from the third table in the SELECT

    Hello

    Union made a distinct in terms of the line. From the line "ALPHA", 2 and the line 'ALPHA', 3 are different, they both show in the result set.

    Further, you are all just lucky, that you get the results you want with the order clause:

    order by 2
    

    This performs a sort on the second column (1,2,3)
    Also, you want to sort on the first column (name1, name2 and Name3). The order clause should be (as already shown correctly abbove):

    order by
      2, 1
    

    Kind regards

    Peter

  • Returns all the duplicate values in object lookup (PHP, drop-down list)

    Hi, I have a PHP page I designed as a search page. I have a number of drop-down lists that get their dynamic values from the fields in a MySQL database.

    At present, if there are any entries that have duplicate values in a certain area, they are all listed, in the order of the index database. For example:

    City:

    Derby

    Stoke

    Stafford

    Stoke

    Derby

    Derby

    Stoke

    etc...

    Now, I want to do is be able to show all results for a given city. In the find what drop-down list box, I would than each of the cities to appear only once rather than every time it is registered. included in this, I would like the page of results to then display ALL results that match this search criteria.

    Thus, in the example above, "Derby" appears only once, but when the user has selected 'Derby', it would return all three results in the results page.

    My results page is built on a dynamic form, so I am confident that the results page would make it according to the needs. However, how can I get the drop-down list box to ask him?

    > 'SELECT DISTINCT table1.champ1, table1.champ2, table1.champ3 FROM Table1 ";

    Duplicate rows to remove the DISTINCT keyword strength SQL. In other words, that it will only return the unique combinations of fields in your selection list. If you examine your results set, you will see that each line is separate, although there may be duplicates in a particular area. Because you want to populate a drop-down list, you must include a field in your select list only, otherwise you get of the dupes.

  • Customize alert messages to check the duplicate value and alert success

    Hi all

    I want to show two alert against the button 'Submit' even at -.

    1 the attention of messages to check the duplicate value and show the duplicate value found alert and
    2 alert if successful the form's success to commit no duplicate values found.

    I did all the thing but what alert-1 show and I pressed the ok button of the alert, then the second alert also shows that I don't want to show.

    Who can I do about it? Have someone to help me!

    Arif

    Use the folliwng in PRE-INSERT-TRIGGER.

    There is not a lot of changes with the exception

    where CANCELLATION_USERID =: CANCELLATION_USERID;

    and

    If valExists > 0 then

    declare
    
     valExists number;
    
    begin
    
     select count(*) into valExists
     from USERDELETION
     where CANCELLATION_USERID = to_char(:CANCELLATION_USERID);
    
     if valExists > 0 then
      message('Duplicate value found !');
      -- show_alert('ERROR_ALERT');
     else
      message('All is well');
      -- show_alert('All is well ');
     end if;
    
    end;
    
  • How to get the values in a single line, without the help of the union

    Hello

    I have a table with the structure and the following data

    EmpID address phoneno emailid
    1001 xyz
    1001 1234234
    1001 [email protected]
    1002 23434
    1002 [email protected]
    1003 abcd
    1003 [email protected]
    1004 [email protected]



    I need to get a result in this format.


    EMP id address phoneno emailid
    1001 xyz 1234234 [email protected]
    1002 23434 [email protected]
    1003 abcd [email protected]
    1004 [email protected]


    I can do this by using the union, but who gives a performance of questions with a large table. I want to do it using any other way using lead or something, but with the relative to data complexity, I couldn't do it.

    Can someone help me please?


    Natarajan

    Published by: Nikita on December 3, 2009 15:50
    Select employee_id, max(address), max(phone), max(email)
    from emp
    group by employee_id;
    

    Max

  • ORA-06550: PLS-00394: wrong number of values in the list INTO a mesh FETCH

    Dear friends,
    I ask you a suggestion:

    The following code inserts a table errors (errori_work), the IDS of the records repeat (in the work of the table), but gives me this error:
    ORA-06550: PLS-00394: wrong number of values in the list of a FETCH statement INTO.

    The work of the table has the 78 columns: the problem of the fields used in the slider flew against the 78% ROWTYPE fields?
    I could use a record declared as the cursor (rec_tabwork cu_tabwork % ROWTYPE;), but in the MANUAL I need a field (ID_WORK) is not present in the cursor.

    declare
    CURSOR cu_tabwork IS
    SELECT CD_STRUTTURA, CD_SUB_STRUTTURA, NR_PRATICA, likelihood
    Work
    CD_STRUTTURA, CD_SUB_STRUTTURA, NR_PRATICA, applications GROUP
    HAVING COUNT (rowid) > 1
    UNION ALL
    SELECT CD_STRUTTURA, CD_SUB_STRUTTURA, NR_PRATICA, likelihood
    Work
    CD_STRUTTURA, CD_SUB_STRUTTURA, NR_PRATICA, applications GROUP
    After HAVING COUNT (rowid) > 2.
    rec_tabwork work % ROWTYPE;
    BEGIN
    Open cu_tabwork;
    loop
    extract the cu_tabwork in rec_tabwork;
    If FOUND then % cu_tabwork
    dbms_output.put_line (rec_tabwork. (ASL); -test
    INSERT INTO errori_work
    (cd_errore, note, ID_WORK)
    )
    VALUES ("ACC", "Record ripetuto nella table work", rec_tabwork.ID_WORK)
    );
    end if;
    EXIT WHEN cu_tabwork % NOTFOUND;
    end loop;
    close cu_tabwork;
    end;

    Can you help me?
    Thank you
    Leo

    Hello

    I loaded your data and ran the query. It's coz the NR_RICETTA contains a null value, so your State A.NR_RICETTA = B.NR_RICETTA will fail when it checks for NULL = NULL. Here is your output from the query

    PRAZY@orcl> select count(ID_AMBS) FROM WORK A
      2  WHERE A.ROWID > ANY (SELECT B.ROWID FROM WORK B
      3  WHERE A.CD_PRESIDIO        =B.CD_PRESIDIO
      4  AND A.GGMM_CONTATTO        =B.GGMM_CONTATTO
      5  AND A.NR_RICETTA   =B.NR_RICETTA
      6  AND A.CD_CONT_PRESCR       =B.CD_CONT_PRESCR
      7  AND A.NR_PROG_INT  =B.NR_PROG_INT
      8  AND A.DESTINAZIONE =B.DESTINAZIONE)
      9  /
    
    COUNT(ID_AMBS)
    --------------
                48
    
    Elapsed: 00:00:00.00
    

    Therefore, I have included NVL to A.NR_RICETTA, which will produce true when it finds null checking 0 = 0 and you will get your result. and this is what you are looking for

    PRAZY@orcl> select count(ID_AMBS) FROM WORK A
      2  WHERE A.ROWID > ANY (SELECT B.ROWID FROM WORK B
      3  WHERE A.CD_PRESIDIO        =B.CD_PRESIDIO
      4  AND A.GGMM_CONTATTO        =B.GGMM_CONTATTO
      5  AND NVL(A.NR_RICETTA,0)    =NVL(B.NR_RICETTA,0)
      6  AND A.CD_CONT_PRESCR       =B.CD_CONT_PRESCR
      7  AND A.NR_PROG_INT  =B.NR_PROG_INT
      8  AND A.DESTINAZIONE =B.DESTINAZIONE)
      9  /
    
    COUNT(ID_AMBS)
    --------------
                61
    
    Elapsed: 00:00:00.01
    

    If you want to insert the duplicate ID in a Table of errors, do an insert with the following select statement.

    INSERT INTO errori_work(cd_errore, note, ID_AMBS)
    SELECT 'CAC', 'Record ripetuto nella tabella Work',ID_AMBS FROM WORK A
    WHERE A.ROWID > ANY (SELECT B.ROWID FROM WORK B
    WHERE A.CD_PRESIDIO     =B.CD_PRESIDIO
    AND A.GGMM_CONTATTO     =B.GGMM_CONTATTO
    AND NVL(A.NR_RICETTA,0)     =NVL(B.NR_RICETTA,0)
    AND A.CD_CONT_PRESCR     =B.CD_CONT_PRESCR
    AND A.NR_PROG_INT     =B.NR_PROG_INT
    AND A.DESTINAZIONE     =B.DESTINAZIONE);
    

    Hope that solves your problem.

    See you soon!

  • How to replace the value of a column in a table based on the value in the second column?

    Hi, I would like to find in a table 2D for values that meet certain criteria (for example, a column< 0.98).=""  based="" on="" which="" rows="" meet="" this="" criteria,="" i="" want="" to="" replace="" the="" values="" in="" a="" different="" column="" of="" the="" array="" (change="" to="" 'nan'="" so="" that="" the="" values="" will="" not="" be="" included="" in="" any="" calculations="" on="" that="" column,="" for="" example="" the="" finding="" the="" mean).=""  i've="" attached="" a="" sample="" .csv="" file.=""  if="" the="" values="" in="" column="" 3="" (index="" 2)="" are="" less="" than="" 0.980="" (or="" some="" other="" user="" defined="" value),="" then="" the="" value="" in="" column="" 2="" (index="" 1)="" should="" be="" replaced="" with="" nan.=""  can="" someone="" help="" out="" with="" this="" search="" and="" replace="">

    Thank you

    Keith

    (using LV 2009 SP1)

    A few quick hits.

    You can merge the two for loops

    You have not need one of the constants 1 and 2 in the index table.  They will solve automatically when you expand on the index picture, once you have wired to 0 in the column index.

    It seems a lot of handling additional table spent unnecessarily.

    See below.  I did not try to duplicate your code to see how it actually works, but I believe that I have attached will give the same result with less steps.

  • Display the name of the tag as the column name and the value in the tag as a row of data from the input string.

    Hi Forum members,

    I am looking for a query display the name of the tag as the column name and the value in the tag as a row of data.

    I have to print the values within the tag to a file by choosing the value of the flags. the sequence of the tags will vary each time, as the tag name will change dynamically.

    So here is the example of input data and the expected output. The string in the text column must be separated as the column names and values.

    Input data
    Select 1 as seqno,' < > 0210A 50 4f < / 4f > < 5f20 > TEST CARD 16 < / 5f20 > < 5f2a > < / 5f2a > < 82 > 1 c 00 < / 82 > ' double text


    Output:

    Seqno 4f 5f20 5f2a 82
    0210A 50 16 1 00 TEST CARD 1

    Please help me by providing your entries on this.

    We use the version of Oracle 11.2.

    Note: This is not the XML string

    Thank you

    Shree

    with

    data in the form of

    (select 1 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2a><82>00 1' text of all the double union)

    Select 2 as seqno,'XYZ<4F>0210 A 50<5f20>TEST CARD 16<5f2a><82>00 1' text of all the double union

    Select 3 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2A><82>1 00XYZ ' text of all the double union

    Select option 4 as seqno,'<4F>0210 A 50<5F20>TEST CARD 16<5f2A><82>1 00XYZ' double text

    )

    Select d.seqno, x.*

    d the data,

    XMLTable ('/ root')

    by the way xmltransform (xmltype ('': replace (replace (text,'<><>'),)))

    XmlType (q'~http://www.w3.org/1999/XSL/Transform "version ="1.0"> ")

                                                     

                                                       

                                                         

                                                       

                                                     

                                                     

                                                       

                                                         

                                                       

                                                     

    ~'

    )

    )

    path of columns '4f' varchar2 (10) "tag4f."

    path of "5f20' varchar2 (30)"tag5f20. "

    path of '5f2a' varchar2 (10) "tag5f2a."

    path of varchar2 (10) "82" "tag82.

    ) x


    SEQNO 4f 5f20 5f2a 82
    1 0210A 50 16 TEST CARD - 1 00
    2 0210A 50 16 TEST CARD - 1 00
    3 0210A 50 16 TEST CARD - 1 00
    4 0210A 50 16 TEST CARD - 1 00

    with

    data in the form of

    (select 1 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2a><82>00 1' text of all the double union)

    Select 2 as seqno,'XYZ<4F>0210 A 50<5f20>TEST CARD 16<5f2a><82>00 1' text of all the double union

    Select 3 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2A><82>1 00XYZ ' text of all the double union

    Select option 4 as seqno,'<4F>0210 A 50<5F20>TEST CARD 16<5f2A><82>1 00XYZ' double text

    ),

    Chopper (seqno, Key, value, String) as

    (select seqno,

    regexp_substr (text,'<(.+?)>', 1, 1, null, 1),

    regexp_substr (Text,'>(.*?))

    regexp_substr (text,'<.+?>. *? ) (.*) $', 1, 1, null, 1). » <>'

    from the data

    Union of all the

    Select seqno,

    regexp_substr (String,'<(.+?)>', 1, 1, null, 1),

    regexp_substr (String,'>(.*?))

    regexp_substr (String,'<.+?>. *? ) (.*) $', 1, 1, null, 1)

    Chopper

    where regexp_substr (string,'<(.*?)>', 1, 1, null, 1) is not null

    )

    Select '4f', seqno, '5f2a', '82', '5f20.

    of (seqno, lower (key) select key, value)

    Chopper

    )

    Pivot (max (value) for key in ('4f' as '4f', '5f20' as '5f20', '5f2a' as '5f2a', "82" as "82"))

    Concerning

    Etbin

  • Range between unbounded preceding: default value of the windowing clause: question

    from online article down: https://oracle-base.com/articles/misc/analytic-functions

    question relates to the part I have in bold below.

    image.png

    There are two things to note here.

    • The addition of the order_by_clause without a windowing_clause means that the query is now return an average race.
    • The default value for windowing_clause is "RANGE BETWEEN UNBOUNDED PRECEDING AND LINE CURRENT", not "ROWS BETWEEN UNBOUNDED PRECEDING AND LINE CURRENT. The fact that it is the BEACH means no LINES, it stops at the first occurrence of the value of the current row, even if it's several lines earlier. Accordingly, the duplicated lines are included in the average when the value of the wage. You can see in the two last records of the 20 Department and the records of the second and the third Department 30



    He mentions including duplicates if the salary is changed. I do not notice a salary in duplicates to change the display of the output, not in salary or individual pay on average (last two documents of the Department 20 for example, both treatments show 3000 respectively). Could someone please clarify this part of the article says it all.



    Watched again and I think I understand...

    Display duplicate is included only once in the average running not twice. What is he trying to tell me?

    I think it is correct but would not rather a bad assumption.

    AVG is not a good example. Just use count:

    SQL > select empno,.

    2 deptno,

    3 sal,

    4 count (*) on rows_cnt (partition by deptno stopped by rows of sal between prior 0 and 0 preceding).

    5 count (*) on range_cnt (partition by deptno arrested by sal ranged from 0 preceding and 0 preceding)

    6 of PEM

    7.

    EMPNO DEPTNO SAL ROWS_CNT RANGE_CNT

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

    7934 10 1300 1 1

    7782 10 2450 1 1

    7839 10 5000 1 1

    7369 20 800 1 1

    7876 20 1100 1 1

    7566 20 2975 1 1

    7788 20 3000 1 2

    7902 20 3000 1 2

    7900 30 950 1 1

    7654 30 1250 1 2

    7521 30 1250 1 2

    EMPNO DEPTNO SAL ROWS_CNT RANGE_CNT

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

    7844 30 1500 1 1

    7499 30 1600 1 1

    7698 30 2850 1 1

    14 selected lines.

    SQL >

    We hope now that you see the difference.

    SY.

  • values based on the following logic 'values after the first values of two '_' and before last '_' values '.

    Hi all

    I need the values according to below 2logics in a single select query using instring and substring

    1 values based on the following logic 'values after the first values of two '_' and before last '_' values '.

    2 values based on the following logic 'values after the first values of two '_' and before last'-'values '.

    EXM:

    Entry: ABCD_EFGH_IJKLM - NOPQ_XYZ output: IJKLM - NOPQ

    Entry:. ABCD_EFGH_IJKLM - NOPQ output:IJKLM

    Thank you.

    Check the following

    WITH DATA1 AS

    (SELECT "ABCD_EFGH_IJKLM - NOPQ_XYZ" double val)

    UNION ALL

    SELECT 'ABCD_EFGH_IJKLM - NOPQ' double val

    )

    SELECT SUBSTR (VAL, INSTR(VAL,'_',1,2) + 1, DECODE (BIGGER (INSTR (VAL, '_',-1, 1), INSTR(VAL,'-',-1,1)), INSTR (VAL,'-', - 1, 1), LENGTH (VAL) + 1, INSTR (VAL, '_',-1, 1))-(INSTR (VAL, '_', 1, 2) + 1))

    OF DATA1;

    Concerning

    Salim

  • update of NULL in the column with the values of the adjacent column

    Examples of data

    with test_data as
    (select 1 as one, null as two, 2 as three,5 as four, 6 as five, null as six from dual
    union all
    select 1 as one, null as two, 2 as three,5 as four, 6 as five, null as six from dual)
    select * from test_data;
    

    This is one of those cases, the case may be where any value of a column can be null

    or two similar columns can be null. If the column is null then I want to update the adjacent column

    average value of the column, if the first column is null so I want to take the next non-null column and update, if the last column is null

    so I want to take prev not zero column and to update.

    In this case would be my expected output

    Un Two Three Four Five Six
    11.52566
    123566

    Prospects for the future the suggesion or advice.

    Or, using Analytics:

    SQL> with test_data (id, one, two, three, four, five, six) as (
      2    select 1, 1   , null, 2   , 5, 6, null  from dual union all
      3    select 2, 1   , null, 3   , 5, 6, null  from dual union all
      4    select 3, 1   , null, null, 5, 6, null  from dual union all
      5    select 4, null, null, null, 5, 6, null  from dual
      6  )
      7  select *
      8  from (
      9    select id
     10         , cell
     11         , case when next_nn is not null and prev_nn is not null
     12             then (next_nn + prev_nn)/2
     13             else nvl(next_nn, prev_nn)
     14           end val
     15    from (
     16      select id
     17           , cell
     18           , val
     19           , last_value(val) ignore nulls over(partition by id order by cell) as prev_nn
     20           , first_value(val) ignore nulls over(partition by id order by cell range between current row and unbounded following) as next_nn
     21      from test_data
     22      unpivot include nulls (val for cell in (one as 1, two as 2, three as 3, four as 4, five as 5, six as 6) )
     23    )
     24  )
     25  pivot ( min(val) for cell in (1 as "ONE", 2 as "TWO", 3 as "THREE", 4 as "FOUR", 5 as "FIVE", 6 as "SIX") )
     26  ;
    
            ID        ONE        TWO      THREE       FOUR       FIVE        SIX
    ---------- ---------- ---------- ---------- ---------- ---------- ----------
             1          1        1,5          2          5          6          6
             2          1          2          3          5          6          6
             3          1          3          3          5          6          6
             4          5          5          5          5          6          6
    
  • Use the value of the sum and compare

    I have a table with data below

    T1

    ID, amount

    12,20

    13,10

    14.5

    create table T1 (ID number, amount);

    Insert into T1

    Select double 12.20;

    Union

    Select 13,10 double;

    Union

    Select double 14.5;

    I need the sum of the quantity and the value of the sum compares the values as flat > display then 10 0 otherwise amounted

    output

    ID, amount, derived

    12,20,20

    13,10,10

    14,5,5

    If my table has a

    T1

    12.0

    13.5

    It should be

    T1

    12,0,0

    13,5,0

    You can use the analytic function SUM

    select id, amount, case when sum(amount) over() > 10 then amount else 0 end derived from t1
    
  • How to upgrade are the value of the column and the new column value created

    Hi all

    create the table xxc_temp

    as

    Select donnees_1 'AB103', 'AAA' data_2 data_3 '123', 'RED' data_4, NULL status in all the double union

    Select donnees_1 'AB105', 'BBB' data_2, '222' data_3, data_4 'BLUE', NULL status in all the double union

    Select donnees_1 'AB106', 'CCC' data_2, '333' data_3, data_4 'BLUE', the double NULL status

    create the table xxc_base

    as

    Select donnees_1 'AB103', 'AAA' data_2, '123' data_3 data_4 'RED', 'Inactive' status of Union double all the

    Select donnees_1 'AB105', 'BBB' data_2, '222' data_3 data_4 'BLUE' status 'Active' of all the double union

    Select donnees_1 'AB106', 'CCC' data_2, '333' data_3, data_4 'BLUE', 'Inactive' status of double

    I need to update the status column xxc_temp with xxc_base value of the status column and also if the user tries to insert new values/lines in the xxc_temp

    So how can I update the status column? I mean automatically set to day and also new values/lines

    I need to update only that are Inactive then these lines should be updated in the temporary table

    We can do this by using the stored function, but I need to update the new status of lines also

    Please help me

    Here's another way to do it, using VIRTUAL function column as expression to get the status of the other table

    CREATE or REPLACE FUNCTION GET_STATUS (pDATA_1 IN TANK) RETURN VARCHAR2 DETERMINISTIC

    AS

    vstatus VARCHAR2 (8);

    BEGIN

    SELECT status in vstatus FROM xxc_base WHERE donnees_1 = pDATA_1;

    RETURN vstatus;

    END;

    /

    DROP TABLE 'XXC_TEMP ';

    CREATE TABLE 'XXC_TEMP '.

    ('DONNEES_1' CHAR (5),

    "DATA_2" TANK (3).

    "DATA_3" TANK (3).

    "DATA_4' VARCHAR2 (4).

    'STATUS' VARCHAR2 (8) GENERATED ALWAYS AS (SUBSTR (GET_STATUS (DATA_1), 1, 8)) VIRTUAL

    ) ;

    INSERT INTO 'XXC_TEMP' (data_3, donnees_1, data_2, data_4))

    Select "AB103' donnees_1, data_2 'AAA', '123' data_3, 'RED' data_4 of any double union

    Select donnees_1 'AB105', 'BBB' data_2, '222' data_3 data_4 'BLUE' of all the double union

    Select donnees_1 'AB106', 'CCC' data_2 data_3 '333', 'BLUE' double data_4);

Maybe you are looking for

  • Incoming Fax page, left thick black line down the side edge

    Hello I recently bought a HP Photosmart 7520 printer and had to return because of a wrong switch ON / OFF the printer.  So I returned and bought another. This second printer works perfectly so far!  However, when I recieive a fax, the page has a very

  • Expansion Slots on HP desktop PC 110-014

    I see on the photos that this motherboard supports 2 slots for memory, but it there any expansion for other video cards slot. I want to run multiple monitors and want to know if I can install a video card external and if so - what technology - PCI/PC

  • STOP: 0 x 00000001 computer stops with error DRIVER_IRQL_NOT_LESS_OR_EQUAL.

    Original title: computer stops with error DRIVER_IRQL_NOT_LESS_OR_EQUAL. computer stops with error DRIVER_IRQL_NOT_LESS_OR_EQUAL STOP: 0x00000001 (0x00000002, 0x00000000, 0x0000000C, 0xf391ca38) Portols.sys address F391CA38 base at F391CA38

  • Spectrum XT Pro PC 13-b000 HP: HP spectrum XT Pro Ultrabook SSD upgrade

    Hello! I currently own the spectrum XT Pro Ultrabook w/4 GB of RAM and 128 GB SSD.  I was wondeirng: (1) if I could move to a larger capacity SSD and if so, what steps I would take to safely install the largest SSD. (2) I also wonder if I can get the

  • Brand new U400 - black screen

    Hello Just got my lenovo u400 today and super excited, however, the screen doesn't seem to work! When I turned on for the first time, I heard it starts but the screen is completely black. I try to use the shortcut key to adjust the brightness, but st