Querying a long column in Oracle

Source: Internet
Author: User

Sql> CREATE TABLE T_long (ID number, long_col LONG);
The table is created.
Sql> INSERT into T_long VALUES (1, Lpad (1, 32767, ' HELLO world! '));
1 rows have been created.
Sql> COMMIT;
Submit complete.
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: Inconsistent data type: number is expected but LONG is obtained
Based on Oracle's recommendations, you should avoid using the long type again. If you should probably use To_lob to rebuild the table, convert the long type in the table to the CLOB or blob type.
This is not the way to think about it, but to discuss how to query for tables that cannot be rebuilt.
If the data in the table does not exceed 32K in length, consider using PL/SQL code similar to the following:
Sql> SET Serverout on
Sql> BEGIN
2 for I in (SELECT * from T_long) LOOP
3 IF INSTR (I.long_col, ' world ') > 0 Then
4 Dbms_output. Put_Line (i.id);
5 END IF;
6 END LOOP;
7 END;
8/
1
The PL/SQL process has completed successfully.
However, the PL/SQL code can handle no more than 32K of data, which exceeds this limit and cannot be processed by PL/SQL.
Fortunately, Oracle's full-text indexing is supported by a long type, and a context index is established, and the query syntax for full-text indexing solves the problem:
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

Querying a long column in Oracle

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.