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
Solved

how to solve this query?

Posted on 2014-07-24
5
209 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
  • 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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL query question 8 92
form builder not starting 3 56
oracle date format checking 7 26
setting local variables in a cursor block 3 20
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

828 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