Solved

How get this query ?

Posted on 2014-07-23
7
335 Views
Last Modified: 2014-07-23
Hi expert,

below i have query
(SELECT regexp_replace('{"1":{"ACC":1,"YBT":"damby}damby"}},"2":{"ACC":1,"YBT":"damby}damby"}},"3":{"ACC":1,"YBT":""}}','^[{"]+|[}"]+$') AS rec
FROM dual
);

Open in new window


result:Result:1":1":{"ACC":1,"YBT":"damby}damby"}},"2":{"ACC":1,"YBT":"damby}damby"}},"3":{"ACC":1,"YBT":
Expected Result: 1":{"ACC":1,"YBT":"damby}damby
                            2":{"ACC":1,"YBT":"damby}damby
                          3":{"ACC":1,"YBT":


Regards
Thomos
0
Comment
Question by:deve_thomos
  • 4
  • 3
7 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 40215072
please as I explained in your other question:

Plase don't post a query that doesn't work and then just assume I'll know what you want it do.

Give me INPUT DATA  (a query is not data)
and expected OUTPUT DATA

along with the parsing rules.

For example of the types of rules I might need:  can you have more than 3 substrings?  How are substrings identified?  Do you need multiple depth searching?

I'm going to assume from your previous question and your query that you want to do {} and " stripping at the outermost level but you haven't specified it here.  

When you post a query and then ask how to get "the query"  you're not giving good enough information.
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 40215157
here's an example of what I would expect...

INPUT:  '{"1":{"ACC":1,"YBT":"damby}damby"}},"2":{"ACC":1,"YBT":"damby}damby"}},"3":{"ACC":1,"YBT":""}}'

Parsing Rule1:  The data is json structured
Parsing Rule 2: Pull each json node out of the string that starts with a { and numeric label "1", "2", "3" and ends with }}
Parsing Rule 3: Return each output as a distinct row with leading and trailing {} and " removed

OUTPUT of 3 rows
1":{"ACC":1,"YBT":"damby}damby
2":{"ACC":1,"YBT":"damby}damby
3":{"ACC":1,"YBT":


Using this example, I would write the query like this...

SELECT REGEXP_REPLACE(
           REGEXP_SUBSTR(
               '{"1":{"ACC":1,"YBT":"damby}damby"}},"2":{"ACC":1,"YBT":"damby}damby"}},"3":{"ACC":1,"YBT":""}}',
               '"[0-9]+".+?}}',
               1,
               LEVEL
           ),
           '^[{"]+|[}"]+$'
       )
           AS rec
  FROM DUAL
CONNECT BY LEVEL <= 3;

Open in new window


That produces the expected results

HOWEVER - since I'm guessing at your parsing rules and structures of your input it doesn't mean it's correct as a general solution, it will only work for this particular string and possibly others with minor changes.
0
 

Author Comment

by:deve_thomos
ID: 40215420
Hi sdstuber,
in this case   you are giving  CONNECT BY LEVEL <= 3;  suppose  my out put is having  10 rows  or more than that  how i will handle that .

Regrads
Thomos
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 73

Expert Comment

by:sdstuber
ID: 40215431
assuming the 10 rows have the same parsing rules that I guessed at then

 CONNECT BY LEVEL <= 3;

becomes

 CONNECT BY LEVEL <= 10;

If the parsing rules are different than my guess then you'll have to do something else but I can't begin to guess what.  

I really am guessing - you haven't described at all what your parsing rules are or confirmed the correct input.

I ask for the same things repeatedly (input, parsing rules, expected output) because it's important.  Trusting me to guess correctly is not a reliable methodology for you.
0
 

Author Comment

by:deve_thomos
ID: 40215454
Hi Sdstuber,
I am parsing some json data , so it can be  one row or it can more than one  row. exact row we cannot say .
in this case  i cannot fix that  CONNECT BY LEVEL <= 10 or CONNECT BY LEVEL <= 3; Then how i will handle this things

if you want  more information  please let me know.

Regards
Thomos
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 40215464
again - assuming MY parsing rules guesses are correct (you haven't confirmed or described your rules) AND the structure of the data will match those rules every time then try something like this.


SELECT *
  FROM (SELECT REGEXP_REPLACE(
                   REGEXP_SUBSTR(
                       '{"1":{"ACC":1,"YBT":"damby}damby"}},"2":{"ACC":1,"YBT":"damby}damby"}},"3":{"ACC":1,"YBT":""}}',
                       '"[0-9]+".+?}}',
                       1,
                       LEVEL
                   ),
                   '^[{"]+|[}"]+$'
               )
                   AS rec
          FROM DUAL
        CONNECT BY LEVEL <= 10)
 WHERE rec IS NOT NULL;


If 10 isn't sufficient for all cases, make it something larger.
Given the 4k limit on varchar2 fields (at least prior to 12c) and given the structure of the json nodes,  it would be impossible for the value to need to be more than 500, but for efficiency you should pick something smaller but still big enough.
0
 

Author Closing Comment

by:deve_thomos
ID: 40215486
Thank u a lot....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PL/SQL Two PAYER_IDs with PAYER_TYPES these two types 4 35
Best RAID for a BDD Oracle 4 62
grouping on time windows 6 43
MULTIPLE DATE QUERY 15 52
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now