deve_thomos
asked on
how to solve below query ?
Hi expert i have below query
json Data: {"1":{"YBG":1,"BNT":"}{}{d g}"},"2":{ "YBG":1,"B NT":"vc}{} }vm"},"3": {"YBG":1," BNT":"vc{} }vm"}}
1":{"YBG":1,"BNT":
2":{"YBG":1,"BNT":"vc}{}}v m
3":{"YBG":1,"BNT":"vc{}}vm
expected output:
1":{"YBG":1,"BNT":}{}{dg
2":{"YBG":1,"BNT":"vc}{}}v m
3":{"YBG":1,"BNT":"vc{}}vm
Regards
Thomos
json Data: {"1":{"YBG":1,"BNT":"}{}{d
SELECT *
FROM (SELECT
REGEXP_REPLACE(
REGEXP_SUBSTR(
:JSONdata,
'"[0-9]+".+?"}',
1,
LEVEL
)
,
'^[{"]+|["}]+$'
)
AS rec
FROM DUAL
CONNECT BY LEVEL <= 11)
WHERE rec IS NOT NULL;
output:1":{"YBG":1,"BNT":
2":{"YBG":1,"BNT":"vc}{}}v
3":{"YBG":1,"BNT":"vc{}}vm
expected output:
1":{"YBG":1,"BNT":}{}{dg
2":{"YBG":1,"BNT":"vc}{}}v
3":{"YBG":1,"BNT":"vc{}}vm
Regards
Thomos
What is different in this question than your other two on this subject:
https://www.experts-exchange.com/questions/28481663/How-to-get-this-query.html
https://www.experts-exchange.com/questions/28482409/How-get-this-query.html
https://www.experts-exchange.com/questions/28481663/How-to-get-this-query.html
https://www.experts-exchange.com/questions/28482409/How-get-this-query.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi ststuber,
see it is working some scenario,
but the problem is
suppose json data is like this
{"1":{"ACC":1,"CNT":"sdvsd vsdvdsvsdv sdvsdvdsvs dvdsvdsvds v"}}
it is giving expected result
but if my json data is like below
{"1":{"ACC":1,"CNT":"}sdvs dvsdvdsvsd vsdvsdvdsv sdvdsvdsvd sv"}}
it is not giving proper result
we need to make dyanamic as a result it should work every json scenario
Regards'
Thomos
see it is working some scenario,
but the problem is
suppose json data is like this
{"1":{"ACC":1,"CNT":"sdvsd
it is giving expected result
but if my json data is like below
{"1":{"ACC":1,"CNT":"}sdvs
it is not giving proper result
we need to make dyanamic as a result it should work every json scenario
Regards'
Thomos
>>>> as a result it should work every json scenario
hahaha, that's funny - no way that can happen.
If you want parsing of anything: json, xml, csv, natural language text, etc - the rules for parsing are dependent on a specific input set.
So, every time you change the structure of the input data you need a new set of parsing rules.
This particular series of questions is special in that you (not oracle) knows the content is json and hence nested entities.
So, what you see as a simple A:B syntax, oracle doesn't. It only sees a string of characters. So you have to teach it, but the rules for identifying A and B are going to be based on the placement of {}, ", [], and commas. However, nesting and interweaving them makes it difficult to identify them for a single string and impossible to do for any string within the context of normal sql.
If you upgrade to 12.1.0.2 it will be A LOT easier. Any version less than that and you'll need to either write a custom sql for the specific structure you're trying to use. Or, get a json parser package (pl/sql, java, c) that you can use from within oracle and then use that.
hahaha, that's funny - no way that can happen.
If you want parsing of anything: json, xml, csv, natural language text, etc - the rules for parsing are dependent on a specific input set.
So, every time you change the structure of the input data you need a new set of parsing rules.
This particular series of questions is special in that you (not oracle) knows the content is json and hence nested entities.
So, what you see as a simple A:B syntax, oracle doesn't. It only sees a string of characters. So you have to teach it, but the rules for identifying A and B are going to be based on the placement of {}, ", [], and commas. However, nesting and interweaving them makes it difficult to identify them for a single string and impossible to do for any string within the context of normal sql.
If you upgrade to 12.1.0.2 it will be A LOT easier. Any version less than that and you'll need to either write a custom sql for the specific structure you're trying to use. Or, get a json parser package (pl/sql, java, c) that you can use from within oracle and then use that.
ASKER
Thanks a lot
Open in new window