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;
}
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
add a comment |
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
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
add a comment |
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
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
sql oracle
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
this will work:
select a.*,REPLACE(a.B, ':', ',') from NS a;
sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0
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
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Nov 23 '18 at 11:30
fa06fa06
19k21019
19k21019
add a comment |
add a comment |
this will work:
select a.*,REPLACE(a.B, ':', ',') from NS a;
sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0
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
add a comment |
this will work:
select a.*,REPLACE(a.B, ':', ',') from NS a;
sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0
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
add a comment |
this will work:
select a.*,REPLACE(a.B, ':', ',') from NS a;
sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0
this will work:
select a.*,REPLACE(a.B, ':', ',') from NS a;
sql fiddle:http://sqlfiddle.com/#!9/2c1e9d/2/0
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 23 '18 at 14:06
jackscorrowjackscorrow
336317
336317
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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