Oracle custom function index trap

Source: Internet
Author: User


The oracle custom function index trap comes from the tip of the iceberg-ORACLE development art conclusion: You must re-build the function index after modifying the function code. Otherwise, oracle will use this function index to query the error results without prompting any errors, which is very limited. [SQL] -- construct TABLE data [SQL] DROP TABLE t; CREATE TABLE t (x NUMBER, y VARCHAR2 (30); INSERT INTO t SELECT ROWNUM, ROWNUM | 'A' FROM dual connect by rownum <100;
[SQL] -- CREATE OR REPLACE FUNCTION f_sing (p_value in VARCHAR2) RETURN VARCHAR2 deterministic IS www.2cto.com BEGIN RETURN p_value;
END; [SQL] -- CREATE a function INDEX and query the result CREATE INDEX idx_f_sing_y ON t (f_sing (y); ANALYZE TABLE t compute STATISTICS FOR TABLE FOR ALL indexes FOR ALL indexed COLUMNS; SELECT * FROM t WHERE f_sing (y) = '8a '; x y 8 8a
[SQL] -- modify the FUNCTION Code create or replace function f_sing (p_value in VARCHAR2) RETURN VARCHAR2 deterministic is begin www.2cto.com RETURN p_value | 'B'; END; [SQL] -- <span style = "color: # ff0000;"> re-query the result and prompt that the function index is disabled. The conclusion in the book is that 8 8a is still found after the function code is modified, this is inconsistent with the original book. Is the version incorrect? </Span> SELECT * FROM t WHERE f_sing (y) = '8a '; 20 1 ORA-30554: function-based index TWGERP. IDX_F_SING_Y disabled
[SQL] -- after the index is disabled using hints, no information is found. This is correct. SELECT/* + no_index (t) */* FROM t WHERE f_sing (y) = '8a '; x y [SQL] -- re-create the index and query results. No data can be found, correct. Drop index idx_f_sing_y; create index idx_f_sing_y ON t (f_sing (y); SELECT * FROM t WHERE f_sing (y) = '8a '; X Y
 

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.