Aggregate function after XMLTABLE returns empty result set





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm having troubles with a query in which I use the LISTAGG() function.



I start from table one in this form:



A   B
1 a:b:e
2 c:d:f


Then I transform it in table two this form:



A  B
1 a
1 b
1 e
2 c
2 d
2 f


Using this query:



SELECT A,
trim(COLUMN_VALUE) B
FROM one,
xmltable(('"'
|| REPLACE(B, ':', '","')
|| '"'))


Then I perform a



SELECT A,
LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
FROM two
GROUP BY A


to go back again to the form:



A    B
1 a,b,e
2 c,d,f


The problem is that in the end the query returns an empty result set:



A    B


Instead of the one I'm expecting.
Unfortunately I can't recreate my problem with a simpler query and I cannot share the original query because it contains sensitive information.



I'm hoping this might be a known problem or maybe related to the field data type. I tried to add a TO_CHAR(B) inside the LISTAGG() function but with no success.










share|improve this question

























  • why are you converting from one table to another just do replace

    – nikhil sugandh
    Nov 23 '18 at 12:17






  • 2





    Your queries work correctly for me (although @nikhilsugandh's comment above and answer below are relevant). Something that you're not showing us is causing the problem, not any of the above. Best of luck.

    – Bob Jarvis
    Nov 23 '18 at 12:21











  • @BobJarvis In my original query I just perform a join with table two in order to filter out some rows later and then I put it back in the original form using LISTAGG. Here I din't include this passage because I've seen that the result is the same even if I don't execute the join, resulting in the steps that I listed above

    – jackscorrow
    Nov 23 '18 at 12:54


















0















I'm having troubles with a query in which I use the LISTAGG() function.



I start from table one in this form:



A   B
1 a:b:e
2 c:d:f


Then I transform it in table two this form:



A  B
1 a
1 b
1 e
2 c
2 d
2 f


Using this query:



SELECT A,
trim(COLUMN_VALUE) B
FROM one,
xmltable(('"'
|| REPLACE(B, ':', '","')
|| '"'))


Then I perform a



SELECT A,
LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
FROM two
GROUP BY A


to go back again to the form:



A    B
1 a,b,e
2 c,d,f


The problem is that in the end the query returns an empty result set:



A    B


Instead of the one I'm expecting.
Unfortunately I can't recreate my problem with a simpler query and I cannot share the original query because it contains sensitive information.



I'm hoping this might be a known problem or maybe related to the field data type. I tried to add a TO_CHAR(B) inside the LISTAGG() function but with no success.










share|improve this question

























  • why are you converting from one table to another just do replace

    – nikhil sugandh
    Nov 23 '18 at 12:17






  • 2





    Your queries work correctly for me (although @nikhilsugandh's comment above and answer below are relevant). Something that you're not showing us is causing the problem, not any of the above. Best of luck.

    – Bob Jarvis
    Nov 23 '18 at 12:21











  • @BobJarvis In my original query I just perform a join with table two in order to filter out some rows later and then I put it back in the original form using LISTAGG. Here I din't include this passage because I've seen that the result is the same even if I don't execute the join, resulting in the steps that I listed above

    – jackscorrow
    Nov 23 '18 at 12:54














0












0








0








I'm having troubles with a query in which I use the LISTAGG() function.



I start from table one in this form:



A   B
1 a:b:e
2 c:d:f


Then I transform it in table two this form:



A  B
1 a
1 b
1 e
2 c
2 d
2 f


Using this query:



SELECT A,
trim(COLUMN_VALUE) B
FROM one,
xmltable(('"'
|| REPLACE(B, ':', '","')
|| '"'))


Then I perform a



SELECT A,
LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
FROM two
GROUP BY A


to go back again to the form:



A    B
1 a,b,e
2 c,d,f


The problem is that in the end the query returns an empty result set:



A    B


Instead of the one I'm expecting.
Unfortunately I can't recreate my problem with a simpler query and I cannot share the original query because it contains sensitive information.



I'm hoping this might be a known problem or maybe related to the field data type. I tried to add a TO_CHAR(B) inside the LISTAGG() function but with no success.










share|improve this question
















I'm having troubles with a query in which I use the LISTAGG() function.



I start from table one in this form:



A   B
1 a:b:e
2 c:d:f


Then I transform it in table two this form:



A  B
1 a
1 b
1 e
2 c
2 d
2 f


Using this query:



SELECT A,
trim(COLUMN_VALUE) B
FROM one,
xmltable(('"'
|| REPLACE(B, ':', '","')
|| '"'))


Then I perform a



SELECT A,
LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
FROM two
GROUP BY A


to go back again to the form:



A    B
1 a,b,e
2 c,d,f


The problem is that in the end the query returns an empty result set:



A    B


Instead of the one I'm expecting.
Unfortunately I can't recreate my problem with a simpler query and I cannot share the original query because it contains sensitive information.



I'm hoping this might be a known problem or maybe related to the field data type. I tried to add a TO_CHAR(B) inside the LISTAGG() function but with no success.







sql oracle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:00







jackscorrow

















asked Nov 23 '18 at 11:26









jackscorrowjackscorrow

336317




336317













  • why are you converting from one table to another just do replace

    – nikhil sugandh
    Nov 23 '18 at 12:17






  • 2





    Your queries work correctly for me (although @nikhilsugandh's comment above and answer below are relevant). Something that you're not showing us is causing the problem, not any of the above. Best of luck.

    – Bob Jarvis
    Nov 23 '18 at 12:21











  • @BobJarvis In my original query I just perform a join with table two in order to filter out some rows later and then I put it back in the original form using LISTAGG. Here I din't include this passage because I've seen that the result is the same even if I don't execute the join, resulting in the steps that I listed above

    – jackscorrow
    Nov 23 '18 at 12:54



















  • why are you converting from one table to another just do replace

    – nikhil sugandh
    Nov 23 '18 at 12:17






  • 2





    Your queries work correctly for me (although @nikhilsugandh's comment above and answer below are relevant). Something that you're not showing us is causing the problem, not any of the above. Best of luck.

    – Bob Jarvis
    Nov 23 '18 at 12:21











  • @BobJarvis In my original query I just perform a join with table two in order to filter out some rows later and then I put it back in the original form using LISTAGG. Here I din't include this passage because I've seen that the result is the same even if I don't execute the join, resulting in the steps that I listed above

    – jackscorrow
    Nov 23 '18 at 12:54

















why are you converting from one table to another just do replace

– nikhil sugandh
Nov 23 '18 at 12:17





why are you converting from one table to another just do replace

– nikhil sugandh
Nov 23 '18 at 12:17




2




2





Your queries work correctly for me (although @nikhilsugandh's comment above and answer below are relevant). Something that you're not showing us is causing the problem, not any of the above. Best of luck.

– Bob Jarvis
Nov 23 '18 at 12:21





Your queries work correctly for me (although @nikhilsugandh's comment above and answer below are relevant). Something that you're not showing us is causing the problem, not any of the above. Best of luck.

– Bob Jarvis
Nov 23 '18 at 12:21













@BobJarvis In my original query I just perform a join with table two in order to filter out some rows later and then I put it back in the original form using LISTAGG. Here I din't include this passage because I've seen that the result is the same even if I don't execute the join, resulting in the steps that I listed above

– jackscorrow
Nov 23 '18 at 12:54





@BobJarvis In my original query I just perform a join with table two in order to filter out some rows later and then I put it back in the original form using LISTAGG. Here I din't include this passage because I've seen that the result is the same even if I don't execute the join, resulting in the steps that I listed above

– jackscorrow
Nov 23 '18 at 12:54












3 Answers
3






active

oldest

votes


















1














You can try below



DEMO



SELECT A,
LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
FROM
(SELECT A,
trim(COLUMN_VALUE) B
FROM one,
xmltable(('"'
|| REPLACE(B, ':', '","')
|| '"'))
) two GROUP BY A


OUTPUT:



A   B
1 a, b, e
2 c, d, f





share|improve this answer































    1














    this will work:



    select a.*,REPLACE(a.B, ':', ',') from NS a;


    sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0






    share|improve this answer
























    • My aim is not to replace the ":" with ",". The example I posted here is a simplification. Once I have my table two I have to filter out some rows and then put it back in the previous form. In my question I din't include this passage because I've seen that the result is the same even if I do just the steps that I listed above

      – jackscorrow
      Nov 23 '18 at 12:52











    • @jackscorrow whats your original question then post that??

      – nikhil sugandh
      Nov 23 '18 at 18:19



















    0














    My hunch about possible data type issues was correct.



    The function xmltable returns a column of type XMLTYPE, in my case column B. The aggregate function failed whenever trying to aggregate a field of that data type.



    I fixed the problem by converting the XMLTYPE column to string obtaining this query:



    SELECT A,
    trim((COLUMN_VALUE).getstringval()) B
    FROM one,
    xmltable(('"'
    || REPLACE(B, ':', '","')
    || '"'))


    Using this query the returned result is correct.



    Many thanks to everybody who tried to help.






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445843%2faggregate-function-after-xmltable-returns-empty-result-set%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You can try below



      DEMO



      SELECT A,
      LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
      FROM
      (SELECT A,
      trim(COLUMN_VALUE) B
      FROM one,
      xmltable(('"'
      || REPLACE(B, ':', '","')
      || '"'))
      ) two GROUP BY A


      OUTPUT:



      A   B
      1 a, b, e
      2 c, d, f





      share|improve this answer




























        1














        You can try below



        DEMO



        SELECT A,
        LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
        FROM
        (SELECT A,
        trim(COLUMN_VALUE) B
        FROM one,
        xmltable(('"'
        || REPLACE(B, ':', '","')
        || '"'))
        ) two GROUP BY A


        OUTPUT:



        A   B
        1 a, b, e
        2 c, d, f





        share|improve this answer


























          1












          1








          1







          You can try below



          DEMO



          SELECT A,
          LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
          FROM
          (SELECT A,
          trim(COLUMN_VALUE) B
          FROM one,
          xmltable(('"'
          || REPLACE(B, ':', '","')
          || '"'))
          ) two GROUP BY A


          OUTPUT:



          A   B
          1 a, b, e
          2 c, d, f





          share|improve this answer













          You can try below



          DEMO



          SELECT A,
          LISTAGG(B, ', ') WITHIN GROUP (ORDER BY B)
          FROM
          (SELECT A,
          trim(COLUMN_VALUE) B
          FROM one,
          xmltable(('"'
          || REPLACE(B, ':', '","')
          || '"'))
          ) two GROUP BY A


          OUTPUT:



          A   B
          1 a, b, e
          2 c, d, f






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 11:30









          fa06fa06

          19k21019




          19k21019

























              1














              this will work:



              select a.*,REPLACE(a.B, ':', ',') from NS a;


              sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0






              share|improve this answer
























              • My aim is not to replace the ":" with ",". The example I posted here is a simplification. Once I have my table two I have to filter out some rows and then put it back in the previous form. In my question I din't include this passage because I've seen that the result is the same even if I do just the steps that I listed above

                – jackscorrow
                Nov 23 '18 at 12:52











              • @jackscorrow whats your original question then post that??

                – nikhil sugandh
                Nov 23 '18 at 18:19
















              1














              this will work:



              select a.*,REPLACE(a.B, ':', ',') from NS a;


              sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0






              share|improve this answer
























              • My aim is not to replace the ":" with ",". The example I posted here is a simplification. Once I have my table two I have to filter out some rows and then put it back in the previous form. In my question I din't include this passage because I've seen that the result is the same even if I do just the steps that I listed above

                – jackscorrow
                Nov 23 '18 at 12:52











              • @jackscorrow whats your original question then post that??

                – nikhil sugandh
                Nov 23 '18 at 18:19














              1












              1








              1







              this will work:



              select a.*,REPLACE(a.B, ':', ',') from NS a;


              sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0






              share|improve this answer













              this will work:



              select a.*,REPLACE(a.B, ':', ',') from NS a;


              sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 23 '18 at 11:44









              nikhil sugandhnikhil sugandh

              1,3542820




              1,3542820













              • My aim is not to replace the ":" with ",". The example I posted here is a simplification. Once I have my table two I have to filter out some rows and then put it back in the previous form. In my question I din't include this passage because I've seen that the result is the same even if I do just the steps that I listed above

                – jackscorrow
                Nov 23 '18 at 12:52











              • @jackscorrow whats your original question then post that??

                – nikhil sugandh
                Nov 23 '18 at 18:19



















              • My aim is not to replace the ":" with ",". The example I posted here is a simplification. Once I have my table two I have to filter out some rows and then put it back in the previous form. In my question I din't include this passage because I've seen that the result is the same even if I do just the steps that I listed above

                – jackscorrow
                Nov 23 '18 at 12:52











              • @jackscorrow whats your original question then post that??

                – nikhil sugandh
                Nov 23 '18 at 18:19

















              My aim is not to replace the ":" with ",". The example I posted here is a simplification. Once I have my table two I have to filter out some rows and then put it back in the previous form. In my question I din't include this passage because I've seen that the result is the same even if I do just the steps that I listed above

              – jackscorrow
              Nov 23 '18 at 12:52





              My aim is not to replace the ":" with ",". The example I posted here is a simplification. Once I have my table two I have to filter out some rows and then put it back in the previous form. In my question I din't include this passage because I've seen that the result is the same even if I do just the steps that I listed above

              – jackscorrow
              Nov 23 '18 at 12:52













              @jackscorrow whats your original question then post that??

              – nikhil sugandh
              Nov 23 '18 at 18:19





              @jackscorrow whats your original question then post that??

              – nikhil sugandh
              Nov 23 '18 at 18:19











              0














              My hunch about possible data type issues was correct.



              The function xmltable returns a column of type XMLTYPE, in my case column B. The aggregate function failed whenever trying to aggregate a field of that data type.



              I fixed the problem by converting the XMLTYPE column to string obtaining this query:



              SELECT A,
              trim((COLUMN_VALUE).getstringval()) B
              FROM one,
              xmltable(('"'
              || REPLACE(B, ':', '","')
              || '"'))


              Using this query the returned result is correct.



              Many thanks to everybody who tried to help.






              share|improve this answer




























                0














                My hunch about possible data type issues was correct.



                The function xmltable returns a column of type XMLTYPE, in my case column B. The aggregate function failed whenever trying to aggregate a field of that data type.



                I fixed the problem by converting the XMLTYPE column to string obtaining this query:



                SELECT A,
                trim((COLUMN_VALUE).getstringval()) B
                FROM one,
                xmltable(('"'
                || REPLACE(B, ':', '","')
                || '"'))


                Using this query the returned result is correct.



                Many thanks to everybody who tried to help.






                share|improve this answer


























                  0












                  0








                  0







                  My hunch about possible data type issues was correct.



                  The function xmltable returns a column of type XMLTYPE, in my case column B. The aggregate function failed whenever trying to aggregate a field of that data type.



                  I fixed the problem by converting the XMLTYPE column to string obtaining this query:



                  SELECT A,
                  trim((COLUMN_VALUE).getstringval()) B
                  FROM one,
                  xmltable(('"'
                  || REPLACE(B, ':', '","')
                  || '"'))


                  Using this query the returned result is correct.



                  Many thanks to everybody who tried to help.






                  share|improve this answer













                  My hunch about possible data type issues was correct.



                  The function xmltable returns a column of type XMLTYPE, in my case column B. The aggregate function failed whenever trying to aggregate a field of that data type.



                  I fixed the problem by converting the XMLTYPE column to string obtaining this query:



                  SELECT A,
                  trim((COLUMN_VALUE).getstringval()) B
                  FROM one,
                  xmltable(('"'
                  || REPLACE(B, ':', '","')
                  || '"'))


                  Using this query the returned result is correct.



                  Many thanks to everybody who tried to help.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 14:06









                  jackscorrowjackscorrow

                  336317




                  336317






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445843%2faggregate-function-after-xmltable-returns-empty-result-set%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                      Alcedinidae

                      Can an atomic nucleus contain both particles and antiparticles? [duplicate]