XMLAGG seperator return twice if the value is null

Hi all

I use the xmlagg function to concatenate the values. If the concatenated field is set to NULL, the separator is to come twice.
Please see the sample data below.

CREATE TABLE emp
(
EmpNo NUMBER,
DEPTNO NUMBER (2)
);

INSERT INTO EMP VALUES (1, 10);
INSERT INTO EMP VALUES (1, 20);
INSERT INTO EMP (empno) VALUES (1);
INSERT INTO EMP VALUES (1, 30);

INSERT INTO EMP VALUES (2, 10);
INSERT INTO EMP VALUES (2, 20);
INSERT INTO EMP (empno) VALUES (2);
INSERT INTO EMP VALUES (2, 40);

Select rtrim (xmlagg (xmlelement (e, deptno |))) (('; .extract ')) ('/ / text()'), '; ') group by empno emp
Output-> 10; 30; 20
* 10; 40; 60.

Oracle version is
Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE Production 11.2.0.3.0
AMT for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

I don't want to display the separator twice, if the NULL value is there in the concatenated column.

Thanks in advance.

Tahnks,
PAL

You can simply add:

where deptno is not null

but it will filter a single occurrence of empno having no deptno, so this should be better:

select rtrim (
         xmlagg (
           case when deptno is not null then
             xmlelement (e,  deptno || '; ')
           end
         ).extract ('//text()')
       , '; '
       )
from emp
group by empno
;

But perhaps a simpler solution is to use LISTAGG (the aggregate string is however limited to 4 k characters):

select empno
     , listagg(deptno, '; ') within group (order by null) as grp
from emp
group by empno
;

Edited by: odie_63 Apr 30. 2012 10:19

Tags: Database

Similar Questions

  • How to check if the value is NULL in the script

    Please, tell which function should I use to check if the value is NULL
    as: If some_member = NULL then...

    Thank you very much

    If you mean #missing:

    Commission (IF (sales <> #MISSING))
    Commission = sales *. 1;
    Another Commission = #MISSING;
    ENDIF ;);

    This example is from the SER60

    PLEASE NOTE: For some reason, the not equals sign does not appear on the first line of the IF statement. (i.e. IF (SALES does not #MISSING))

  • Return custom results, the value of the service

    Hi all

    Can return us customized results, the value of a personalized service?

    We plan to write a wrapper for the Service of research and return the result set custom when that service is called. Any body tried this approach before and do you know what are the advantages and disadvantages of this approach.

    1. resources Service file. CheckReleaseState is the personal name of resultset.

    2 file query of the resource.

    Run your custom service and then access the resultset in java using the line below:

    DataResultSet searchDataResultSet = new DataResultSet();

    searchDataResultSet.copy (binder.getResultSet ("CheckReleaseState"));

  • error checking the value of NULL attribute on viewObject

    Hello
    am on jdev 11.1.2.3
    in my case I would check whether or not a viewObject attribute is null, an error pops up when the value of the attribute is null and this for all types of data in all locations (bean, ViewRowImpl class class EntityImpl):

    < BuildFacesMessage > ADF: addition of the following JSF error: java.lang.NullPointerException

    for example:
    I've used this control but even pbs
    If (! this.getDatRem () m:System.NET.SocketAddress.ToString () .isEmpty ()) {}
    .....
    }

    Thank you

    Copy the following code

    if (!this.getDatRem==null) {
    //---------------------------
    .....
    }
    
  • Cell borders disappear when the value is null

    I'm now a PL/SQL report. When the value of a column is null, the cell borders disappear. I would have preferred that they do not disappear.

    Any suggestions?
  • List of selection with redirection sets the values to null

    I saw another post with a similar issue. However, the answer given does not work for me.

    I have a "Site" text field whose value depends on a list of select 'customer '. I am able to set the value of "Site" based on the select list with redirect. However, other values on this page are reset to null.

    I saw an answer that says to change the display of selection list type to "select the list to submit." But this type of display requires a page that deals with the process is created. This solution did not help either.

    Any solution?

    If you follow this example, you will be able to set the status of the session without redirection / layout page:

    http://Apex.Oracle.com/pls/OTN/f?p=31517:229

    Denes Kubicek
    ------------------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    ------------------------------------------------------------------------------

  • How to assign a value zero if the value is null.

    I have a package, procedure and many functions. I'm trying to get the result of DBMS to list a value for each, if it is null, assign it a zero and move.
    I can't find examples where I can do. Any ideas on how I can assign a zero when there is no value in the table?
    CREATE OR REPLACE PACKAGE emp_net_pay IS
      PROCEDURE emp_tot_sal  (v_empno IN NUMBER);
      FUNCTION find_emp      (v_empno IN NUMBER) RETURN BOOLEAN;
      FUNCTION tot_sal_com   (v_empno IN NUMBER) RETURN NUMBER;
      FUNCTION bef_tax_ded   (emp_no IN NUMBER)  RETURN NUMBER;
      FUNCTION temp_sal_btd  (emp_no IN NUMBER)  RETURN NUMBER;
      FUNCTION tax_emp_sal   (emp_no IN NUMBER)  RETURN NUMBER;
      FUNCTION sal_aft_tax   (emp_no IN NUMBER)  RETURN NUMBER;
      FUNCTION aft_tax_ded   (emp_no IN NUMBER)  RETURN NUMBER;
      FUNCTION tot_net_sal   (emp_no IN NUMBER)  RETURN NUMBER;
    END emp_net_pay;
    /
    CREATE OR REPLACE PACKAGE BODY emp_net_pay IS
    --Procedure calculates totals: Salary plus commission
    PROCEDURE emp_tot_sal (v_empno IN NUMBER)
    IS
      v_tot_sal  NUMBER;
      v_bef_ded  NUMBER;
      v_temp_sal NUMBER;
      v_tot_tax  NUMBER;
      v_sal_tax  NUMBER;
      v_aft_ded  NUMBER;
      v_net_sal  NUMBER;
     BEGIN
      v_tot_sal  := tot_sal_com (v_empno);
      v_bef_ded  := bef_tax_ded (v_empno);
      v_temp_sal := temp_sal_btd(v_empno);
      v_tot_tax  := tax_emp_sal (v_empno);
      v_sal_tax  := sal_aft_tax (v_empno);
      v_aft_ded  := aft_tax_ded (v_empno);
      v_net_sal  := tot_net_sal (v_empno);
         DBMS_OUTPUT. PUT_LINE ('Salary before deductions for employee # ' || v_empno || ' equal: ' || to_char(v_tot_sal,'$999,999.99'));
         DBMS_OUTPUT. PUT_LINE ('Before tax deductions for    employee # ' || v_empno || ' equal: ' || to_char(v_bef_ded,'$999,999.99'));
         DBMS_OUTPUT. PUT_LINE ('Salary minus deductions for  employee # ' || v_empno || ' equal: ' || to_char(v_temp_sal,'$999,999.99'));
         DBMS_OUTPUT. PUT_LINE ('Total taxes for              employee # ' || v_empno || ' equal: ' || to_char
    (v_tot_tax,'$999,999.99'));
         DBMS_OUTPUT. PUT_LINE ('Salary minus taxes for       employee # ' || v_empno || ' equal: ' || to_char
    (v_sal_tax,'$999,999.99'));
         DBMS_OUTPUT. PUT_LINE ('After tax deductions for     employee # ' || v_empno || ' equal: ' || to_char(v_aft_ded,'$999,999.99'));
         DBMS_OUTPUT. PUT_LINE ('Net salary for               employee # ' || v_empno || ' equal: ' || to_char
    (v_net_sal,'$999,999.99'));
     END emp_tot_sal; 
    ..................................................
    Salary before deductions for employee # 7369 equal:      $900.00
    Before tax deductions for    employee # 7369 equal:       $95.34
    Salary minus deductions for  employee # 7369 equal:      $804.66
    Total taxes for                   employee # 7369 equal:       $56.33
    Salary minus taxes for          employee # 7369 equal:      $748.33
    After tax deductions for       employee # 7369 equal:        $8.00
    Net salary for                      employee # 7369 equal:      $740.33
    *******************************************************
    
    alary before deductions for employee # 7654 equal:    $2,650.00
    efore tax deductions for    employee # 7654 equal:
    alary minus deductions for  employee # 7654 equal:
    otal taxes for                    employee # 7654 equal:
    alary minus taxes for          employee # 7654 equal:
    fter tax deductions for       employee # 7654 equal:
    et salary for                      employee # 7654 equal:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    NVL looking for [url http://docs.oracle.com/cd/B28359_01/olap.111/b28126/dml_functions_2048.htm]?

  • Search for users using java API IOM 11 with the value of null field

    Hello

    I find user using java api findUsers (HashMap hash), but I need get all users where a custom field is equal to null

    Example:

    HashMap userHash = new HashMap();
    userHash.put ("USR_UDF_CUSTOM", "NULL");
    userData tcResultSet = userOps.findUsers (userHash);

    Someone help me?

    Do not use this search functionality. The user that:

    UserManager usermgr = Platform.getService (UserManager.class);
    Criteria of SearchCriteria = new SearchCriteria ("Custom Label", null, SearchCriteria.Operator.EQUAL); Suppose USR_UDF_CUSTOM label is personalized
    List of users of = usermgr.search (null, null, criteria);
    for (user: user) {}
    perform the action here
    }

    -Kevin

  • How to enter text in a numeric field if the value is null

    This is probably very simple, but I can't seem to find the answer. I am using LiveCycle Designer 7.0.

    I have a numeric field that calculates the percentage change between two other fields of digital type. Because the denominator of the equation can be zero, I placed the calculation in a 'If, Then, Else' statement. However, I can't "n/m" text to display in the form, if the divisor (PYGasSales) is equal to zero. Is someone can you please tell me what I am missing in this statement?

    if(PYGasSales ne 0) then
    (YGasSalesVar/PYGasSales) * 100
    else 
    "n/m"
    endif

    Thank you very much!

    You can try using the text field instead of using the digital field.

    Text field can show the text and figures.

    Numeric field can show numbers.

    Danash

  • Medium need to return false if a value has not yet been written.

    I am a new user of labVIEW here looking for a way to return false if the value has not yet been written.

    I am using the "select" tool to swap between values early enough in my simulation. However, it requires data that has not happened yet, so I need something that is waiting for the value to write.

    Is it possible to use a while loop to wait until TRUE or FALSE (instead of NULL) has been written and then change the frequency?

    All instances of data in LabVIEW (controls, terminals, constants, shift registers etc.) have a value, there is no concept of NULL.

    A Boolean control, before write you, will be its default value (probably false). A string will be empty (but not NULL, it is always valid). A digital will be zero, a reference is not valid (possibly equivalent to NULL, but this terminology is not used.)

    Can you describe your needs more detail, I don't understand what you need to do.

    If you want to wait for a change in value (Boolean to change true), then survey (read several times) from the Terminal command in a while loop with it connected directly to the terminal of condiitional. Its default value of False will cause the while loop loop continuously until the value is set to True. I would advise to insert a short wait inside the loop so that it hoggig a CPU.

  • How to get the value with DBSequence in EL links

    Hello

    I have a DBSequence type id and check if the value is null or positive

    #{bindings. Id.inputValue! = null and links. Id.inputValue > 0? {"Edit": "Create"} does not work because the links. Id.inputValue returns a DBSequence and cannot convert Long

    How to get the value?

    JDev 11.1.1.6

    You can try this:

    #{bindings. Id.inputValue.sequenceNumber.value! = null and links. Id.inputValue.sequenceNumber.value > 0? {'Edit': 'Create'}

    Jean Lou

  • Sustaining the values of point unchanged after a "set-point and redirect.

    I use the instance online on apex.oracle.com

    I have a form that looks like this:

    Name: < text field >
    Type: < select list >
    Property1: < select list >

    When Type is changed, a "set-point and redirect" are performed.

    The source of Property1 is determined by the value of Type. This means that whenever the Type is changed, the Property1 value could change.

    'Name' is not affected. The problem is when I change the 'name' and then change 'Type', the action "Set the value and redirect" returns 'Name' to the value it had when the first load of the page.

    The question is: is it possible to ensure that the 'name' retains some value it had just before "the set value and redirect" was carried out?

    Thank you.

    popovitsj wrote:
    I use the instance online on apex.oracle.com

    I have a form that looks like this:

    Name:
    Type:

    When Type is changed, a "set-point and redirect" are performed.

    The source of Property1 is determined by the value of Type. This means that whenever the Type is changed, the Property1 value could change.

    'Name' is not affected. The problem is when I change the 'name' and then change 'Type', the action "Set the value and redirect" returns 'Name' to the value it had when the first load of the page.

    The question is: is it possible to ensure that the 'name' retains some value it had just before "the set value and redirect" was carried out?

    Create it Type and Property1 by using the ability of LOV cascade integrated rather than try to to re-create yourself.

  • Access the value of a [Text Input with LOV] in an ADF application Panel

    Hello

    I have a QUERY with id (queryId1) in which I filter data in a table based on search criteria. The search name of the employee.

    I would like to take this [Input Text with LOV] element value and use it in a method (the method 'myMethod' is a bean called 'myBean'). The method must also check for a NULL value value. If no criteria have been entered, (in other words, the value is NULL), an exception should be thrown. Otherwise a popup should be displayed showing the name of the selected employee.

    I should mention that I'm rather new to ADF (experience of the 1 month!) but I tried to get this working put in place three days without success. I've been all over the internet, but my lack of understanding is perhaps to my disadvantage. I was wondering if someone here might be able to send me a link on how to do so, or explain in detail how this can be done. I have also sought tutorials on YouTube but have found none.

    I work with JDeveloper Version 11.1.2.1.0

    I'm not allowed to change the version currently.

    Thank you in advance!

    Kind regards

    Riana

    Maybe this can help:

    http://www.Oracle.com/technetwork/developer-tools/ADF/learnmore/85-QueryComponent-fieldvalidation-427197.PDF

    https://blogs.Oracle.com/aramamoo/entry/interpret_af_query_s_queryevent

    Dario

  • Getting the value null inserted in the back end when the field is turned off

    Hi gurus,

    I have a TOTAL field that is the sum of the other two fields in a form. I have disabled because do not have the user enter the value. The TOTAL field is the poster of the sum of the values in the front end, but in the back-end, the value is null. Please help me solve this problem. Thanks in advance.

    Have you tried to make the point read-only? Set the read-only item and try. You can do the unalterable element by two methods,

    (1) amend section-> go to read only tab-> read-only Condition Type: always

    (2) create a dynamic Action-> event: loading the Page-> Action: run the JavaScript Code-> Code:

    $('#P1_TEST').attr ('readOnly', true);

    $('#P1_TEST').css ('background-color', '#CDCDCD');

    Tom wrote:

    set the item read-only instead (not editable by the user but will present)

    Set the element value using the da no need to activate the item before submitting because the element is not disabled. Make the point read-only so that it will submit the value to the session and point cannot be changed always.

    Thank you

    Lacombe

  • Compare the value of the column with the previous column and Populate values

    Hi all


    Please help me to get the required sql

    I have a table T1 as example below

    Id1 Id2 Column1 Column2
    1 1 name1 null
    1 2 name2 XYZ
    1 3 name3 null
    1 4 name4 abc
    1 5 name5 null



    If the value is null, ishould then fill with the previous value. until he finds a following value.
    The result should be as below

    Id1 Id2 Column1 Column2
    1 1 name1 null
    1 2 name2 XYZ
    1 3 name3 XYZ
    1 4 name4 abc
    1 5 abc name5

    Please help me to get the required sql

    Thanks in advance

    Hello

    Here's one way:

    SELECT    id1
    ,       id2
    ,       column1
    ,       LAST_VALUE (column2  IGNORE NULLS)
                     OVER ( PARTITION BY  id1          -- if needed
                                ORDER BY         id2
                       )        AS column2
    FROM      t1
    ORDER BY  id1, id2                         -- if needed
    ;
    

    I'm guessing only a few things, as what makes a line 'previous' or 'next '.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using. «LAST_VALUE...» IGNORE NULLS"requires that Oracle 10.1 or higher.

Maybe you are looking for

  • Satellite C850-F31Q - touchpad has stopped working

    This is the 5th time I use my laptop. (Just for 4 weeks now) My touchpad / mouse pad does not work anymore. I tried to install the new drivers, but still no luck. I'm running of Windies 7 and also have a (thankfully) - wireless mouse but it gives als

  • Satellite A200-1UV: deleted Microsoft Office - how to get it again?

    Hi - I deleted the version of Microsoft Office when I received my 1UV satellite A200. I deleted Microsoft Office because I thought that it would be incompatible with Open Office, as I had just installed. I can get Microsoft Office on my laptop and ho

  • Split x 2 turns off when I move

    About two months ago, I bought this HP X 2 split.  When I'm working on it, if I move and the screen moves very slightly backward, it stops completely.  I have to adjust the screen at an angle where the power button turns on it.

  • The Service WCF and Blackberry Widget does not. See where I am going wrong?

    I'm creating a widget of BB with Visual Studio 2008 and I created a WCF Service hosted in Windows Azure. This is one of the methods in the WCF Service: public string ClockIn(string emailAddress) { try { using (var dc = new TEI_DataContext(_MyDc)) { S

  • go to 7 7 NetBook has started on reformatting Dominican Republic

    New - searched and searched. I have a netbook aspire one d270. I bought the upgrade on the net. I have a product key, I also have a virus: the upgrade of the internet reformat my drive? I don't want to be a pest, but I do not have a disk, I don't hav