Oracle 隱式轉換


Oracle在執行自隱式轉換時:總是會把字符串轉為數字,字符串轉為日期。當列進行轉換,會跳過索引,降低性能。

  1. 創建一個表格,給三個列建立索引,進行測試。
create table t1(n1 number, v1 varchar2(10), d1 date);

insert into t1
  select
        rownum n1
      , rownum v1
      , sysdate + dbms_random.value(0,365)
  from
        dual
connect by level <= 1e3;


create index t1_n1_idx on t1(n1);
create index t1_v1_idx on t1(v1);
create index t1_d1_idx on t1(d1);
View Code
  • 查看執行計划,v1列因為隱式to_number,所以沒有走索引
select count(1) from t1 where v1 = 1

 

下面的走索引T1_V1_IDX

select count(1) from t1 where v1 = '1'

  • 查看執行計划,因為v1列需要轉日期,所以不走索引

只要列不轉類型,就走索引

 

 

總結自:https://www.red-gate.com/simple-talk/sql/oracle/oracle-data-type-implicit-conversion-hierarchy/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM