Query for long columns in Oracle __oracle

Source: Internet
Author: User
Tags create index

Sql> CREATE TABLE T_long (ID number, long_col LONG);   Table has been created.   Sql> INSERT into T_long VALUES (1, Lpad (1, 32767, ' HELLO world! '));   1 lines have been created.   Sql> COMMIT;   Submit completed.   Sql> SELECT * from T_long WHERE long_col like '%world% ' 2; SELECT * from T_long WHERE long_col like '%world% ' * error on line 1th: ORA-00932: Data type inconsistency: should be number, but get LONG based on Oracle's recommendation, You should avoid using the long type again.   If you might want to use TO_LOB to rebuild a table, convert a long type in the table to a CLOB or blob type.   This method is not considered here, just to discuss how to query for tables that cannot be rebuilt. If the data in the table is not longer than 32K, consider implementing the following Pl/sql code like this: sql> SET serverout on sql> BEGIN 2 to I in (SELECT * from T_long) L OOP 3 IF INSTR (I.long_col, ' world ') > 0 THEN 4 dbms_output.   Put_Line (i.id);   5 End IF;   6 End LOOP;   7 End;   The 8/1 Pl/sql process has completed successfully.   However, Pl/sql code can only handle no more than 32K of data, beyond this limit, can not be processed through pl/sql. Fortunately, Oracle's Full-text indexing supports a LONG type, creating a context index that can be solved by using the Full-text indexed query syntax: sql> CREATE INDEX ind_t_long_col on T_long (Long_col) Indextype is Ctxsys.   context;   The index has been created. Sql> SELECT ID from T_long WHERE CONTAINS (Long_col, ' World ') > 0; ID----------1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.