How to query a CLOB column in Oracle

前端 未结 8 1448
鱼传尺愫
鱼传尺愫 2020-11-27 06:24

I\'m trying to run a query that has a few columns that are a CLOB datatype. If i run the query like normal, all of those fields just have (CLOB) as the value.

8条回答
  •  攒了一身酷
    2020-11-27 06:48

    If it's a CLOB why can't we to_char the column and then search normally ?

    Create a table

    CREATE TABLE MY_TABLE(Id integer PRIMARY KEY, Name varchar2(20), message clob);
    

    Create few records in this table

    INSERT INTO MY_TABLE VALUES(1,'Tom','Hi This is Row one');
    INSERT INTO MY_TABLE VALUES(2,'Lucy', 'Hi This is Row two');
    INSERT INTO MY_TABLE VALUES(3,'Frank', 'Hi This is Row three');
    INSERT INTO MY_TABLE VALUES(4,'Jane', 'Hi This is Row four');
    INSERT INTO MY_TABLE VALUES(5,'Robert', 'Hi This is Row five');
    COMMIT;
    

    Search in the clob column

    SELECT * FROM MY_TABLE where to_char(message) like '%e%';
    

    Results

    ID   NAME    MESSAGE   
    ===============================  
    1    Tom     Hi This is Row one         
    3    Frank   Hi This is Row three
    5    Robert  Hi This is Row five
    

提交回复
热议问题