Is there a PL/SQL pragma similar to DETERMINISTIC, but for the scope of one single SQL SELECT?(是否有类似于 DETERMINISTIC 的 PL/SQL pragma,但仅针对单个 SQL SELECT 的范围?)
问题描述
在 SQL SELECT 语句中,我想执行一个对该 SELECT 语句的范围具有确定性的函数(或者事务也可以):
In a SQL SELECT statement, I'd like to execute a function that is deterministic for the scope of that SELECT statement (or transaction would be ok, too):
select t.x, t.y, my_function(t.x) from t
t.x 的许多值是相同的,因此 Oracle 可以省略一次又一次地调用相同的函数,以加快速度.但是,如果我将该函数标记为 DETERMINISTIC,则结果可能会在多次执行此查询之间缓存.之所以不能使用DETERMINISTIC,是因为my_function使用了一个不时变化的配置参数.
Many values of t.x are the same so Oracle could omit calling the same function again and again, to speed things up. But if I label the function as DETERMINISTIC, the results may be cached between several executions of this query. The reason why I can't use DETERMINISTIC is because my_function uses a configuration parameter that is changed from time to time.
我可以使用其他关键字吗?是否有任何我应该注意的问题(内存问题、并发性等)?或者可能有任何其他技巧,例如每个 t.x 值仅调用一次函数的分析函数(对性能没有重大影响)?
Is there any other keyword I could use? Are there any catches that I should be aware of (memory issues, concurrency, etc)? Or maybe any other tricks, such as analytic functions to call the function only once per t.x value (without major performance impact)?
推荐答案
如果你这样做:
select t.x, t.y, (select my_function(t.x) from dual)
from t
然后Oracle可以使用子查询缓存来实现减少函数调用.
then Oracle can use subquery caching to achieve reduced function calls.
这篇关于是否有类似于 DETERMINISTIC 的 PL/SQL pragma,但仅针对单个 SQL SELECT 的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有类似于 DETERMINISTIC 的 PL/SQL pragma,但仅针对单个 SQL SELECT 的范围?
基础教程推荐
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
