`

oracle中的deterministic关键字

 
阅读更多
转自:http://www.anbob.com/?p=820

  今天学习物化视图,在Oracle9.2.0.0上遇到这个问题,但在9.2.0.8上没有这个问题。就上网查了查,又新掌握了点知识。

SQL> conn zwz
Enter password:
Connected.
SQL> desc testfun;
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
ID                                                 NUMBER(38)
NAME                                               VARCHAR2(22)

SQL> select * from testfun;

ID NAME
---------- ----------------------
1 anbob.com
2 anbob.com
3 weijar.com

SQL> create or replace function f_upp(p_name varchar2)
2  return varchar2
3is
4begin
5return  upper(p_name);
6  end;
7  /

Function created.

SQL> create index idx_f_upp on testfun(f_upp(name));
create index idx_f_upp on testfun(f_upp(name))
*
ERROR at line 1:
ORA-30553: The function is not deterministic

SQL> create or replace function f_upp(p_name varchar2)
2  return varchar2 deterministic
3  begin
4    return upper(p_name);
5* end;

Warning: Function created with compilation errors.

SQL> show err
Errors for FUNCTION F_UPP:

LINE/COL ERROR
-------- -----------------------------------------------------------------
3/1      PLS-00103: Encountered the symbol "BEGIN" when expecting one of
the following:
; is authid as cluster order using external deterministic
parallel_enable pipelined aggregate
The symbol "is" was substituted for "BEGIN" to continue.

SQL>l2
2* return varchar2 deterministic
SQL> input is
SQL> l
1  create or replace function f_upp(p_name varchar2)
2  return varchar2 deterministic
3  is
4  begin
5    return upper(p_name);
6* end;
SQL> run
1  create or replace function f_upp(p_name varchar2)
2  return varchar2 deterministic
3  is
4  begin
5    return upper(p_name);
6* end;

Function created.

SQL> create index idx_f_upp on testfun(f_upp(name));

Index created..
Specify DETERMINISTIC to indicate that the function returns the same result value whenever it is called with the same values for its arguments.

You must specify this keyword if you intend to call the function in the expression of a function-based index or from the query of a materialized view that is marked REFRESH FAST or ENABLE QUERY REWRITE. When Oracle Database encounters a deterministic function in one of these contexts, it attempts to use previously calculated results when possible rather than reexecuting the function. If you subsequently change the semantics of the function, you must manually rebuild all dependent function-based indexes and materialized views.

这个关键字表明:如果你的函数当输入一样时,会返回同样的结果.
这样, 数据库就用前一个计算的值,而不需要再重新计算一次.
这对于使用函数索引等,会得到相当大的好处.

英文说明:

DETERMINISTIC Clause

Specify DETERMINISTIC to indicate that the function returns the same result value whenever it is called with the same values for its arguments.

You must specify this keyword if you intend to call the function in the expression of a function-based index or from the query of a materialized view that is marked REFRESH FAST or ENABLE QUERY REWRITE. When Oracle Database encounters a deterministic function in one of these contexts, it attempts to use previously calculated results when possible rather than reexecuting the function. If you subsequently change the semantics of the function, you must manually rebuild all dependent function-based indexes and materialized views.

Do not specify this clause to define a function that uses package variables or that accesses the database in any way that might affect the return result of the function. The results of doing so will not be captured if Oracle Database chooses not to reexecute the function.

The following semantic rules govern the use of the DETERMINISTIC clause:

You can declare a top-level subprogram DETERMINISTIC.

You can declare a package-level subprogram DETERMINISTIC in the package specification but not in the package body.

You cannot declare DETERMINISTIC a private subprogram (declared inside another subprogram or inside a package body).

A DETERMINISTIC subprogram can call another subprogram whether the called program is declared DETERMINISTIC or not.
分享到:
评论

相关推荐

    oracle日历转化成农历

    在Oracle中,虽然没有内置的直接转换函数来实现这一功能,但可以通过自定义函数或者利用现有的开源存储过程来实现这一转换。下面我们将详细介绍如何在Oracle中进行阳历到农历的转换。 首先,我们需要理解阳历和农历...

    数据库关键字保留字大全

    这里收录了多种数据库管理系统中的保留字,包括DB2、Oracle、MySQL、SQL Server等。这些保留字是数据库管理系统中不可或缺的一部分,理解和熟悉这些保留字对数据库的设计、开发和管理至关重要。 DB2保留字 DB2是...

    IEEE 802.11s - Mesh Deterministic Access

    ### IEEE 802.11s - Mesh Deterministic Access (MDA) #### 概述 IEEE 802.11s标准是一项为无线局域网(WLAN)提供透明广播域支持的协议,其核心特性之一是Mesh Deterministic Access(MDA),即确定性网格访问...

    Deterministic PD Compliance MOI 1.pdf

    文档中反复提及的“Deterministic”一词,意味着测试过程中的行为是可以预测和一致的,这对于确保USB PD设备之间的兼容性和可靠性至关重要。由于USB PD技术在不同设备和应用场景中发挥着重要作用,因此对设备的合规...

    Oracle XML DB之浅入浅出

    在Oracle数据库中,XML DB 是一种用于存储、查询和管理 XML 数据的强大工具。为了开始使用这一功能,首先需要完成 XML DB 的安装。 ##### 1.1 通过DBCA安装 **DBCA(Database Configuration Assistant)** 是 ...

    Deep deterministic strategy gradient.py

    在OpenAI的gym环境中,利用深度强化学习的DDPG算法实现立杆子的小游戏仿真,验证算法的效果,加有注释适合初学者,同时可以适应tensorflow2.x版本运行

    #1418-该函数的声明中没有DETERMINISTIC,NO SQL或READS SQL DATA,并且启用了二进制日志记录(您*可能*希望使用不太安全的log_bin_trust_function_creators ...

    在标题中提到的问题是关于函数声明的特性,特别是`DETERMINISTIC`、`NO SQL`和`READS SQL DATA`这些关键字的缺失,以及在启用二进制日志记录(Binary Logging)时可能遇到的安全问题。 首先,我们来解释一下这些...

    mysql 报错This function has none of DETERMINISTIC解决方案

    MySQL中的“DETERMINISTIC”标识符是用来定义存储过程或函数的一个特性,它表示该函数在相同的输入参数下总是返回相同的结果。当你尝试创建或修改一个存储过程,并且MySQL服务器启用了二进制日志(binlog)功能,...

    ArcSDE vs Oracle Spatial

    可以通过多种方式将空间数据导入到 Oracle Spatial 数据库中,包括使用 SQL*Loader 或者通过 OGC Web 服务接口等。 **4. 基于 SDO_GEOMETRY 的 ST_GEOMETRY** 尽管 `SDO_GEOMETRY` 是 Oracle Spatial 的核心几何...

    ORACLE表自动按月分区步骤

    在Oracle数据库中,为了优化大型数据表的查询性能和管理效率,可以采用分区技术。分区是一种将大表逻辑上划分为较小、更易管理的部分的方法。对于时间序列数据,如交易记录、日志数据等,按月分区尤其常见,因为这...

    Network Caculus A Theory of Deterministic Queuing Systems for the Internet

    该书的PDF版本(0 BOOK Network Caculus A Theory of Deterministic Queuing Systems for the Internet v4.pdf)应该包含了详细的概念阐述、数学推导和实例分析,是网络工程领域的重要参考资料。

    DOA估计 - DML(deterministic ML) & SML(stochastic ML)

    标题中的"DOA估计 - DML(deterministic Maximum Likelihood) & SML(stochastic Maximum Likelihood)"是指在信号处理领域中的方向-of-arrival (DOA)估计算法,这两种方法都是用于确定多天线接收系统中多个信号源的...

    mathematics applied to deterministic problems in the natural sciences.djvu

    尤其值得称赞的是,对于一个问题,书中都会给出各种解法,然后分析各种解法的优劣,如果算法没有达到预期的结果,会分析是什么导致了错误的结果。 希望这本书能帮助大家学习。 由于本人能力有限,不能上传大于20MB的...

    一种改进的SMT模拟器——支持Oracle机制和多种取指策略.pdf

    而Oracle研究,顾名思义,就像是数据库中的Oracle数据库一样,是一种技术手段,用于提供问题解决方案的最优解和最差解,帮助研究者对研究问题进行全面的评估。 文章中提到的三种取指策略各自有着不同的特点和应用...

    把Regular Expression 转换为Non-deterministic Finite Automata(NFA)

    这个程序是把正则表达式用图形的方式表达出来。用户输入一个正则表达式,程序会自动为这个正则表达式画出相应的图形来。 这个程序的正则表达式支持所有的字母 “*”符号表示循环。 含有数字的正则表达式是不合法的。

    MySQL创建自定义函数有关问题

    然而,在创建自定义函数时,可能会遇到一些问题,比如“此函数在声明中没有DETERMINISTIC、NO SQL或READS SQL DATA,并且二进制日志已启用”的错误。本文将深入探讨这个错误的原因以及如何解决它。 首先,让我们...

    概率论排队论确定性模型Deterministic model和例题

    概率论排队论确定性模型Deterministic model和例题

Global site tag (gtag.js) - Google Analytics