Solved

Substring from Clob or Blob column

Posted on 2014-09-08
3
384 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 74

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 74

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

749 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