博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle OCP 1Z0-050(39题)解析
阅读量:4040 次
发布时间:2019-05-24

本文共 3608 字,大约阅读时间需要 12 分钟。

Oracle OCP 1Z0-050(39题)解析

QUESTION 39:

Evaluate the following function code:

CREATE FUNCTION get_dept_avg(dept_id NUMBER)

RETURN NUMBER

RESULT_CACHE RELIES_ON (EMPLOYEES)

IS

avgsal NUMBER(6);

BEGIN

SELECT AVG(SALARY)INTO avgsal

FROM EMPLOYEES

WHERE DEPARTMENT_ID = dept_id;

RETURN avgsal;

END get_dept_avg;

Which statement is true regarding the above function?

A. The cached result becomes invalid when any structural change is done to the EMPLOYEES table.

B. If the function is invoked with a different parameter value, the existing result in the result cache gets overwritten by the latest value.

C. Each time the function is invoked in a different session, the current result in the result cache gets overwritten.

D. If the function execution results in an unhandled exception, the exception result is also stored in the cache.

Answer: A

解析:

这个题目定义了一个PLSQL函数get_dept_avg,并且使用了RESULT_CACHE RELIES_ON子句,当EMPLOYEES表的结构发生改变时,缓存的结果集信息就无效了。

PL/SQL 函数高速缓存使用:

(1)  在程序包的函数声明部分或函数定义中包括RESULT_CACHE选项。

(2)  可以选择包括RELIES_ON 子句,以指定函数结果依赖的任何表或视图。

 

例如:

CREATE OR REPLACE FUNCTION productName(prod_id NUMBER, lang_id VARCHAR2)RETURN NVARCHAR2RESULT_CACHE RELIES_ON (product_descriptions)ISresult VARCHAR2(50);BEGINSELECT translated_name INTO resultFROM product_descriptionsWHERE product_id = prod_id AND language_id= lang_id;RETURN result;END;

使用说明:

(1)如果函数的执行导致了未处理的异常错误,该异常结果不会存储在高速缓存中。

(2)在以下情况下执行高速缓存结果的函数主体:

- 此数据库实例上的会话第一次使用这些参数值调用该函数。这些参数值的高速缓存结果无效。

- 当在函数定义的RELIES_ON 子句中指定的任何数据库对象发生更改时,高速缓存的结果就会失效。

- 这些参数值的高速缓存结果已过时。如果系统需要更多内存,它可能会放弃最早的高速缓存值。

- 该函数绕过高速缓存。

(3)该函数不应有任何负作用。

(4)该函数不应依赖特定于会话的设置。

(5)该函数不应依赖特定于会话的应用程序上下文。

参考Oracle官方文档

Developing Applications with Result-Cached Functions

When developing an application that uses a result-cached function, make no assumptions about the number of times the body of the function will run for a given set of parameter values.

Some situations in which the body of a result-cached function runs are:

  • The first time a session on this database instance invokes the function with these parameter values

  • When the cached result for these parameter values is invalid

    When a change to any data source on which the function depends is committed, the cached result becomes invalid.

  • When the cached results for these parameter values have aged out

    If the system needs memory, it might discard the oldest cached values.

  • When the function bypasses the cache (see )

 

Restrictions on Result-Cached Functions

To be result-cached, a function must meet all of these criteria:

  • It is not defined in a module that has invoker's rights or in an anonymous block.

  • It is not a pipelined table function.

  • It is recommended that a result-cached function also meet these criteria:

  • It has no side effects.

    For information about side effects, see .

  • It does not depend on session-specific settings.

    For more information, see .

  • It does not depend on session-specific application contexts.

    For more information, see .

  •  
  • It does not reference dictionary tables, temporary tables, sequences, or nondeterministic SQL functions.

    For more information, see .

  • It has no OUT or IN OUT parameters.

  • No IN parameter has one of these types:

    • BLOB

    • CLOB

    • NCLOB

    • REF CURSOR

    • Collection

    • Object

    • Record

  • The return type is none of these:

    • BLOB

    • CLOB

    • NCLOB

    • REF CURSOR

    • Object

    • Record or PL/SQL collection that contains an unsupported return type

Examples of Result-Cached Functions

The best candidates for result-caching are functions that are invoked frequently but depend on information that changes infrequently (as might be the case in the first example). Result-caching avoids redundant computations in recursive functions.

Examples:

 

转载地址:http://wytdi.baihongyu.com/

你可能感兴趣的文章
Java高并发,如何解决,什么方式解决
查看>>
深入理解分布式事务,高并发下分布式事务的解决方案
查看>>
分布式事务一些总结与思考
查看>>
Spring Cloud微服务架构实践与经验总结
查看>>
Spring Boot入门篇
查看>>
spring cloud服务的注册与发现(Eureka)
查看>>
Java IO流
查看>>
多线程
查看>>
互联网产品设计:产品即服务
查看>>
UrlreWirte的使用
查看>>
使用js定位到页面某个位子
查看>>
java获取客户端真实ip
查看>>
SWFUPLOAD的使用(java版)
查看>>
Memcached的使用(基于java)
查看>>
java ee中的乱码问题及解决方案
查看>>
从技术到管理:思维转变是关键
查看>>
spring2.5.6下配置定时器
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
mongdb安装使用
查看>>