Solved

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

Posted on 2016-09-14
4
49 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
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

771 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

7 Experts available now in Live!

Get 1:1 Help Now