【发布时间】:2020-09-02 17:30:27
【问题描述】:
问题:
Oracle SQL - 我有 2 个选择查询(比如 SQ1 和 SQ2)。 SQ1 和 SQ2 都选择一个 ID 值,但具有不同的连接条件、差异表和 where 条件。
场景 1:如果 SQ1 返回 1 行,则使用 select 语句的结果对表进行更新。 如果 SQ1 返回 0 行或多于 1 行,则控制应转到方案 2。
场景 2:如果 SQ2 返回 1 行,则使用 SQ2 语句的结果对表进行更新。 如果 SQ2 返回 0 或 >1 个结果,则调用另一个包过程。
如何将最少的上下文切换到数据库?
我是如何编码的:
select count(*) into v_count from table; ---SQ1
case if v_count=1 ...then do this...
Else
select count(*) into v_count2 from table; ---SQ2
--2nd case starts here
case if
v_count2=1 ...then do this...
else call package.procedure.
end case;
end case;
要求
对数据库的调用最少。减少上下文切换。
【问题讨论】:
标签: sql oracle oracle-sqldeveloper query-optimization context-switch