Solved

Oracle 12c SQL - Finding a specific string in a long data type column

Posted on 2016-09-14
4
114 Views
Last Modified: 2016-09-16
Hello Experts,

I need to search for a specific string within a long data type field. The text contained within the field usually looks like:

BOND INFORMATION
 
Arrest Bond Added to Case with:
Action Code: AGGRAVATED DISORDERLY CONDUCT
Arrest Date: 07/21/2016
Bond Status: BOND SET
Status Date: 07/21/2016
Blanket Bond: No
Okay to Apply: No
Bond Type: PERSONAL BOND
 
Charge #1: AGGRAVATED DISORDERLY CONDUCT

I need to find entries that include the text string: Bond Status: BOND SET

...of course when I use basic syntax like:

select d.dkt_text
from dkt d
where d.dkt_text like '%BOND SET%'
and d.dt >= to_date('01-jan-2016');

I get the error message: ORA-00932: inconsistent datatypes: expected NUMBER got LONG
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:
Error at Line: 3 Column: 7

Is it possible to extract a specific string value from a long data type column?
0
Comment
Question by:jsmith08
[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
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41798957
try dbms_lob.instr()
select d.dkt_text
from dkt d
where dbms_lob.instr(d.dkt_text,'BOND SET') > 0
and d.dt >= to_date('01-jan-2016','dd-mmm-yyyy')

Open in new window

ps, ALWAYS use date format masks in the to_date function
0
 

Author Comment

by:jsmith08
ID: 41799170
Thank you. I copied your example above and I received the following error message:

ORA-00997: illegal use of LONG datatype
00997. 00000 -  "illegal use of LONG datatype"
*Cause:    
*Action:
Error at Line: 3 Column: 22

Thanks also for the advice about using a date format mask with the to_date function.
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 41799199
The LONG data type is deprecated and you cannot use LIKE with that data type.
 
You also can't use functions designed for CLOB data types
 (my original suggestion assume a CLOB)

You can use TO_LOB() to convert the LONG to CLOB

Then you can use my suggestion.

refs.
https://www.experts-exchange.com/questions/21520838/how-to-find-a-substring-in-a-long-datatype.html

https://www.experts-exchange.com/questions/28268466/find-a-string-in-a-long-column.html#a39576747
0
 

Author Comment

by:jsmith08
ID: 41802320
Thank you for your help and suggestions. I have decided that this will be more involved than is necessary for my assignment. I am going to close the question.
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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to recover a database from a user managed backup

732 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