[sql] Search for a particular string in Oracle clob column

How to get a particular string from a clob column?

I have data as below which is stored in clob column called product_details

CALCULATION=[N]NEW.PRODUCT_NO=[T9856] 
OLD.PRODUCT_NO=[T9852].... -- with other text

I would like to search for string NEW.PRODUCT_NO from column product_details

I have tried as

select * from my_table
where dbms_lob.instr(product_details,'NEW.PRODUCT_NO')>=1

The above fetches full text from my table.

Any help is highly appreciable.

Regards

This question is related to sql oracle oracle10g clob

The answer is


You can just CAST your CLOB value into a VARCHAR value and make your querie like a


ok, you may use substr in correlation to instr to find the starting position of your string

select 
  dbms_lob.substr(
       product_details, 
       length('NEW.PRODUCT_NO'), --amount
       dbms_lob.instr(product_details,'NEW.PRODUCT_NO') --offset
       ) 
from my_table
where dbms_lob.instr(product_details,'NEW.PRODUCT_NO')>=1;

Below code can be used to search a particular string in Oracle clob column

select *  
from RLOS_BINARY_BP
where dbms_lob.instr(DED_ENQ_XML,'2003960067') > 0;

where RLOS_BINARY_BP is table name and DED_ENQ_XML is column name (with datatype as CLOB) of Oracle database.


select *  
from TABLE_NAME
where dbms_lob.instr(COLUMNNAME,'searchtext') > 0;

You can use the way like @Florin Ghita has suggested. But remember dbms_lob.substr has a limit of 4000 characters in the function For example :

dbms_lob.substr(clob_value_column,4000,1)

Otherwise you will find ORA-22835 (buffer too small)

You can also use the other sql way :

SELECT * FROM   your_table WHERE  clob_value_column LIKE '%your string%';

Note : There are performance problems associated with both the above ways like causing Full Table Scans, so please consider about Oracle Text Indexes as well:

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/ccapp/indexing-with-oracle-text.html


Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to oracle

concat yesterdays date with a specific time ORA-28001: The password has expired how to modify the size of a column How to create a blank/empty column with SELECT query in oracle? Find the number of employees in each department - SQL Oracle Query to display all tablespaces in a database and datafiles When or Why to use a "SET DEFINE OFF" in Oracle Database How to insert date values into table error: ORA-65096: invalid common user or role name in oracle In Oracle SQL: How do you insert the current date + time into a table?

Examples related to oracle10g

Query to display all tablespaces in a database and datafiles How to insert date values into table Why do I get PLS-00302: component must be declared when it exists? ORA-28000: the account is locked error getting frequently Oracle Trigger ORA-04098: trigger is invalid and failed re-validation Inserting Image Into BLOB Oracle 10g Error System.Data.OracleClient requires Oracle client software version 8.1.7 or greater when installs setup Different CURRENT_TIMESTAMP and SYSDATE in oracle Search for a particular string in Oracle clob column ORA-00984: column not allowed here

Examples related to clob

Difference between CLOB and BLOB from DB2 and Oracle Perspective? Search for a particular string in Oracle clob column Error : ORA-01704: string literal too long Extract data from XML Clob using SQL from Oracle Database ORA-00932: inconsistent datatypes: expected - got CLOB How to convert CLOB to VARCHAR2 inside oracle pl/sql Java: How to insert CLOB into oracle database Disabling contextual LOB creation as createClob() method threw error How to query a CLOB column in Oracle Most efficient solution for reading CLOB to String, and String to CLOB in Java?