Oracle参数问题(使用OR Opeator)

时间:2017-07-28 14:52:25

标签: oracle oracle11g oracle-sqldeveloper

如果我单独执行两个查询,则不需要4秒来获取数据,但是当两者结合时,我看到查询是deadslow。任何帮助非常感谢

<applicationPools>
        <add name="DefaultAppPool" managedRuntimeVersion="v4.0" />
        <add name="Classic .NET AppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
        <add name=".NET v2.0 Classic" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
        <add name=".NET v2.0" managedRuntimeVersion="v2.0" />
        <add name=".NET v4.5 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
        <add name=".NET v4.5" managedRuntimeVersion="v4.0" />
        <add name="FinancialHub" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
          <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
        </add>
        <applicationPoolDefaults managedRuntimeVersion="v4.0">
            <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="false" />
        </applicationPoolDefaults>
    </applicationPools>

2 个答案:

答案 0 :(得分:0)

如果你查看所有3个语句的执行计划,你就会弄清楚。如果你没有兴趣搞清楚并且你必须只执行一个查询,那么你可以执行这个,使用src来确定哪个行下面哪些行假设你必须知道差异并假设数字和名称是合适的等效数据类型:

Select 1 src, Med_Number,Member_Name,DOB
FROM Med
WHERE Med.Med_Number=:Med_Number
UNION ALL
Select 2 src, Red_Number,Red_Name, null
FROM Red 
WHERE Red.Red_Number=:Red_Number

当然,如果数据类型是等价的并且DOB不允许为null,那么这就足够了

Select Med_Number,Member_Name,DOB
FROM Med
WHERE Med.Med_Number=:Med_Number
UNION ALL
Select Red_Number,Red_Name, null
FROM Red 
WHERE Red.Red_Number=:Red_Number

答案 1 :(得分:0)

当您在m.Med_number = R.Red_number上加入两个表格时,您不需要2个参数。

Select Med_Number,Member_Name,Red_Number,Red_Name FROM Med M
LEFT JOIN Red R ON M.Med_Number=R.Red_Number
Where M.Med_Number=:Number;