我是靠谱客的博主 幸福白羊,最近开发中收集的这篇文章主要介绍oracle查询使用or,查询视图,使用or就用不上索引,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

select * from taccoinfo c where (c.c_identityno = '32128319820406203X'

or c.c_identityno = fchangeidentityno('32128319820406203X'));

使用or 就会全表扫描,使用and会能用上索引,请问怎么优化?

CRM_PERSONAL_CUST和CRM_ORG_CUST表的CERTCODE和ORGCERTCODE是有索引的

视图sql

create or replace view taccoinfo as

select /*+ index(CRM_ACCOINFO) */

SYSDATE AS C_MODIFYDATE,

'-' AS C_MAILZIP,

'-' AS C_MAILADDRESS,

'-' AS C_HOMEPHONE,

'-' AS C_CORPPHONE,

'-' AS L_BILLTIME,

'-' AS L_MBILLTIME,

'-' AS L_SBILLTIME,

'-' AS C_EMOBILEPHONE,

'-' AS C_EEMAIL,

'-' AS C_EMAILADDRESS,

'-' AS C_UNPHONE,

to_char(a.CUSTID) as c_custno,

a.ACCOUNTTYPE as c_accounttype,

a.FUNDACCOUNT as c_fundacco,

a.TACHANNELID as c_agencyno,

'-' as c_netno,

'-' as c_childnetno,

a.OPENDATE as d_opendate,

a.ACCOUNTSTATUS as c_accostatus,

'-' as c_freezecause,

TO_DATE('18990101', 'YYYYMMDD') as d_backdate,

999999999 AS L_CHANGETIME,

TO_DATE('18990101', 'YYYYMMDD') as d_firstinvest,

'-' as c_password,

substr('1',0,1) as c_custtype,

b.CUSTNAME as c_custname,

b.CUSTSIMPLENAME as c_shortname,

TO_CHAR('-') as c_helpcode,

b.CERTTYPE as c_identitytype,

b.CERTCODE as c_identityno,

b.POSTCODE as c_zipcode,

b.ADDRESS as c_address,

b.HOMEPHONE as c_phone,

b.FAX as c_faxno,

b.MOBILE as c_mobileno,

b.EMAIL as c_email,

b.SEX as c_sex,

TO_CHAR(b.BIRTH, 'YYYYMMDD') as c_birthday,

b.WORK as c_vocation,

decode(b.SCHOOLAGE, '00','01','01','02','02','03','03','04','QT') as c_education,

b.YEAREARNING as c_income,

b.AGENTNAME as c_contact,

b.AGENT_CERTTYPE as c_contype,

b.AGENT_CERTCODE as c_contno,

decode(e.c_billsendflag,'按季','3','2') as c_billsendflag,

'-' as c_callcenter,

'-' as c_internet,

'-' as c_secretcode,

'-' as c_nationality,

b.CITY as c_cityno,

'-' as c_lawname,

'-' as c_shacco,

'-' as c_szacco,

'-' as c_broker,

'-' as f_agio,

b.REMARK as c_memo,

'-' as c_reserve,

'-' as c_corpname,

b.PHONE as c_corptel,

'-' as C_SPECIALCODE,

'-' as c_actcode,

a.BILLSENDPASS as c_billsendpass,

'-' as c_bill,

'-' as c_checked,

'-' as l_serialno,

b.RELATIONGRADE as c_viplevel,

decode(substr(a.FUNDACCOUNT, 1,2), '10', '10','99','99', '98') as c_tano,

(case when e.c_billsendflag = '不寄送' or e.c_billsendflag = '强制不寄送' then '1' else '0' end) as c_billsend,

'-' as c_bank_acconame,

'-' as c_bank_accono,

'-' as c_bank,

'-' as  l_trglimit,

'-' as c_modifyfrom,

'-' as c_modifyoperator,

TO_DATE('18990101', 'YYYYMMDD') as d_lastmodify,

'-' as C_BILLMISS,

'-' as C_BOURSEFLAG,

'-' as C_CUSTOMER_MEMO,

'-' as C_MANUALFLAG,

'-' as C_OTHERFUND,

'-' as C_SEND,

'-' as C_UNEMAIL,

'-' as C_UNSMS,

'-' as C_WRONGMOBILENO,

'-' as c_SERVICEUSER,

'0' as c_throwaway,

'9' as c_servicetype,

to_date('20991231', 'yyyymmdd') as d_idnovaliddate,

null as c_bp,

b.C_SPECIALACCOUNT as C_SPECIALACCOUNT,

'0'  as c_billsendpost,

'' as  c_recommender,

'' as  c_recommendertype

from CRM_ACCOINFO a ,CRM_PERSONAL_CUST b,crm_contactor e

where to_char(b.CUSTID)=to_char(a.CUSTID) and e.objectid = b.CUSTID

and e.contactortype = '0' --客户联系人

and e.role='1' --主联系人

--***********CRM_ORG_CUST表关联*******************

union ALL

select /*+ index(CRM_ACCOINFO) */

SYSDATE AS C_MODIFYDATE,

'-' AS C_MAILZIP,

'-' AS C_MAILADDRESS,

'-' AS C_HOMEPHONE,

'-' AS C_CORPPHONE,

'-' AS L_MBILLTIME,

'-' AS L_SBILLTIME,

'-' AS L_BILLTIME,

'-' AS C_EMOBILEPHONE,

'-' AS C_EEMAIL,

'-' AS C_EMAILADDRESS,

'-'  AS C_UNPHONE,

to_char(c.CUSTID) as c_custno,

c.ACCOUNTTYPE as c_accounttype,

c.FUNDACCOUNT as c_fundacco,

c.TACHANNELID as c_agencyno,

to_char('-') as c_netno,

'-'  as c_childnetno,

c.OPENDATE as d_opendate,

c.ACCOUNTSTATUS as c_accostatus,

TO_CHAR('-') as c_freezecause,

TO_DATE('18990101', 'YYYYMMDD') as d_backdate,

999999999 AS L_CHANGETIME,

TO_DATE('18990101', 'YYYYMMDD')  as d_firstinvest,

'-'  as c_password,

substr('0',0,1) as c_custtype,

d.CUSTNAME as c_custname,

d.CUSTSIMPLENAME as c_shortname,

TO_CHAR('')  as c_helpcode,

d.ORGCERTTYPE as c_identitytype,

d.ORGCERTCODE as c_identityno,

d.POSTCODE as c_zipcode,

d.ADDRESS as c_address,

d.PHONE as c_phone,

d.FAX as c_faxno,

TO_CHAR('')  as c_mobileno,

d.URL as c_email,

'-'  as c_sex,

'-' as c_birthday,

'-' as c_vocation,

'-'  as c_education,

'-'  as c_income,

d.DEALER_NAME as c_contact,

'-'  as c_contype,

'-'  as c_contno,

decode(f.c_billsendflag,'按季','3','2') as c_billsendflag,

'-' as c_callcenter,

'-' as c_internet,

'-' as c_secretcode,

d.COUNTRY as c_nationality,

d.CITY as c_cityno,

d.ARTIFICAL as c_lawname,

'-' as c_shacco,

'-' as c_szacco,

'-'  as c_broker,

'-' as f_agio,

d.REMARK as c_memo,

'-'  as c_reserve,

'-'  as c_corpname,

d.PHONE as c_corptel,

'-'  as C_SPECIALCODE,

'-'  as c_actcode,

'-'  as c_billsendpass,

'-' as c_bill,

'-'  as c_checked,

'-' as l_serialno,

d.RELATIONGRADE  as c_viplevel,

decode(substr(c.FUNDACCOUNT, 1,2), '10', '10','99','99', '98') as c_tano,

(case when f.c_billsendflag = '不寄送' or f.c_billsendflag = '强制不寄送' then '1' else '0' end) as c_billsend,

'-'  as c_bank_acconame,

'-'  as c_bank_accono,

'-'  as c_bank,

'-' as l_trglimit,

'-'  as c_modifyfrom,

'-' as c_modifyoperator,

TO_DATE('18990101', 'YYYYMMDD') as d_lastmodify,

'-' as C_BILLMISS,

'-' as C_BOURSEFLAG,

'-' as C_CUSTOMER_MEMO,

'-' as C_MANUALFLAG,

'-' as C_OTHERFUND,

'-' as C_SEND,

'-' as C_UNEMAIL,

'-' as C_UNSMS,

'-' as C_WRONGMOBILENO,

'-' as c_SERVICEUSER,

'0' as c_throwaway,

'9' as c_servicetype,

to_date('20991231', 'yyyymmdd') as d_idnovaliddate,

null as c_bp,

d.C_SPECIALACCOUNT as C_SPECIALACCOUNT,

'0'  as c_billsendpost,

'' as  c_recommender,

'' as  c_recommendertype

from CRM_ACCOINFO c

, CRM_ORG_CUST d , crm_contactor f

where  to_char(c.CUSTID)=to_char(d.CUSTID) and f.objectid = c.CUSTID

and f.contactortype = '0' --客户联系人

and f.role='1' --主联系人;

最后

以上就是幸福白羊为你收集整理的oracle查询使用or,查询视图,使用or就用不上索引的全部内容,希望文章能够帮你解决oracle查询使用or,查询视图,使用or就用不上索引所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部