Solved

how to solve this query?

Posted on 2014-07-24
5
213 Views
Last Modified: 2014-07-27
Hi expert,
below is my query
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;

Open in new window


jsondata is given here :
 {"1":{"YBG":1,"BNT":"vc{//}}vm"},"2":{"YBG":1,"BNT":"vc}{}}vm"},"3":{"YBG":1,"BNT":"vc{}}vm"}}

Open in new window


Note:Note:inside 'vcvm'  IF i give any special character . it will take a whole string it should not trim any characters
result:
1":{"YBG":1,"BNT":"vc{//}vm"},"2":{"YBG":1,"BNT":"vc}{
3":{"YBG":1,"BNT":"vc{

expected result:
 1":{"YBG":1,"BNT":"vc}{//}vm
 2":{"YBG":1,"BNT":"vc}{}}vm
 3":{"YBG":1,"BNT":"vc}{}}vm

Regards
Thomos
0
Comment
Question by:deve_thomos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40217348
I get the expected results.

Below is my test case (use sqlplus against an 11.2.0.2 database) and my results.

My guess is whatever you are using to execute the SQL is interpreting the double slashes in some way.



SQL> var JSONdata varchar2(100)
SQL>
SQL> exec :JSONdata := '{"1":{"YBG":1,"BNT":"vc{//}}vm"},"2":{"YBG":1,"BNT":"vc}{}}vm"},"3":{"YBG":1,"BNT":"vc{}}vm"}}'

PL/SQL procedure successfully completed.

SQL> SELECT *
  2    FROM (SELECT REGEXP_REPLACE(
  3                     REGEXP_SUBSTR(
  4                         :JSONdata,
  5                         '"[0-9]+".+?}}',
  6                         1,
  7                         LEVEL
  8                     ),
  9                     '^[{"]+|[},]+&'
 10                 )
 11                     AS rec
 12            FROM DUAL
 13          CONNECT BY LEVEL <= 11)
 14   WHERE rec IS NOT NULL;

1":{"YBG":1,"BNT":"vc{//}}
2":{"YBG":1,"BNT":"vc}{}}
3":{"YBG":1,"BNT":"vc{}}

Open in new window

0
 

Author Comment

by:deve_thomos
ID: 40217360
hello slight wv

see my  expeceted output:
1":{"YBG":1,"BNT":"vc}{//}vm
 2":{"YBG":1,"BNT":"vc}{}}vm
 3":{"YBG":1,"BNT":"vc}{}}vm

your output:
1":{"YBG":1,"BNT":"vc{//}}
2":{"YBG":1,"BNT":"vc}{}}
3":{"YBG":1,"BNT":"vc{}}

After  that  all charecters 'vm' characters are missing.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40217370
Missed that.

Let me work on it.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40217387
You had a typo from the solution in your previous question.

Based on the new requirement try this:
var JSONdata varchar2(100)

exec :JSONdata := '{"1":{"YBG":1,"BNT":"vc{//}}vm"},"2":{"YBG":1,"BNT":"vc}{}}vm"},"3":{"YBG":1,"BNT":"vc{}}vm"}}'


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;

Open in new window

0
 

Author Closing Comment

by:deve_thomos
ID: 40223468
Thanks a lot...
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to take different types of Oracle backups using RMAN.

707 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