Solved

Substring from Clob or Blob column

Posted on 2014-09-08
3
374 Views
Last Modified: 2014-09-15
I have a table with blob column which stores all comments entered by users for particular assest (asset01)

CommentHeaderuser1 CommentDate2014-08-15-14.48.14.000000
CommentDateStageNbr20StageNbrCommentHeaderCommentBodytest 1 - first test CommentBody

CommentHeaderuser2 CommentDate2014-08-15-14.13.08.000000
CommentDateStageNbr20StageNbrCommentHeaderCommentBodyTest 2 - Second TestCommentBody

User 1 entered comments test 1 - first test which is stored between commentbody and commentbody
User 2 eneterd Test 2 - Second Test which is stored between commentbody
How to query using sql to get these comments as seperate lines
Line 1 - Test 1 - FirstTest
Line 2 - Test 2 - Second Test


Table contains multiple assets and each asset will have comments stored in tags
0
Comment
Question by:raana jella
  • 2
3 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 40311278
SELECT REPLACE(
           REGEXP_SUBSTR(
               comments,
               'CommentBody.+CommentBody',
               1,
               x.COLUMN_VALUE
           ),
           'CommentBody'
       )
  FROM yourtable,
       TABLE(
           (SELECT COLLECT(LEVEL)
              FROM DUAL
            CONNECT BY LEVEL <= REGEXP_COUNT(yourtable.comments, 'CommentBody.+CommentBody'))
       ) x
 WHERE asset = 'asset01'
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 500 total points
ID: 40311282
and another version that doesn't require regular expressions, but same basic idea


SELECT asset, SUBSTR(comments, s, e - s)
  FROM (SELECT asset,
               comments,
                 INSTR(
                     comments,
                     'CommentBody',
                     1,
                     COLUMN_VALUE * 2 - 1
                 )
               + LENGTH('CommentBody')
                   s,
               INSTR(
                   comments,
                   'CommentBody',
                   1,
                   COLUMN_VALUE * 2
               )
                   e
          FROM yourtable,
               TABLE(
                   (SELECT COLLECT(LEVEL)
                      FROM DUAL
                    CONNECT BY INSTR(
                                   comments,
                                   'CommentBody',
                                   1,
                                   LEVEL * 2
                               ) != 0)
               ) x
         WHERE asset = 'asset01');
0
 

Author Comment

by:raana jella
ID: 40312030
Thank you,
I will try these solutions and will let you know
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.

Join & Write a Comment

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
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…

757 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

19 Experts available now in Live!

Get 1:1 Help Now