• OCP-1Z0-053-V12.02-54题


    54.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 execution results in an unhandled exception, the exception result is also stored in the

    cache.

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

    overwritten.

    D. If the function is invoked with a different parameter value, the existing result in the result cache gets

    overwritten by the latest value.

    Answer: A



    Enabling Result-Caching for a Function

    To make a function result-cached, include the RESULT_CACHE clause in the function definition. (If you declare the function before defining it, you must also include the RESULT_CACHE option in the function declaration.)

    In Example 8-37, the package department_pkg declares and then defines a result-cached function, get_dept_info, which returns a record of information about a given department. The function depends on the database tables DEPARTMENTS and EMPLOYEES.

    Example 8-37 Declaring and Defining Result-Cached Function

    CREATE OR REPLACE PACKAGE department_pkg IS
     
      TYPE dept_info_record IS RECORD (
        dept_name  departments.department_name%TYPE,
        mgr_name   employees.last_name%TYPE,
        dept_size  PLS_INTEGER
      );
     
     
    -- Function declaration
     
      FUNCTION get_dept_info (dept_id PLS_INTEGER)
        RETURN dept_info_record
     
    RESULT_CACHE
    ;
     
    END department_pkg;
    /
    CREATE OR REPLACE PACKAGE BODY department_pkg IS
     
    -- Function definition
      FUNCTION get_dept_info (dept_id PLS_INTEGER)
        RETURN dept_info_record
     
    RESULT_CACHE RELIES_ON (DEPARTMENTS, EMPLOYEES)
      IS
        rec  dept_info_record;
      BEGIN
        SELECT department_name INTO rec.dept_name
        FROM departments
        WHERE department_id = dept_id;
     
        SELECT e.last_name INTO rec.mgr_name
        FROM departments d, employees e
        WHERE d.department_id = dept_id
        AND d.manager_id = e.employee_id;
     
        SELECT COUNT(*) INTO rec.dept_size
        FROM EMPLOYEES
        WHERE department_id = dept_id;
     
        RETURN rec;
      END get_dept_info;
    END department_pkg;
    /

    You invoke the function get_dept_info as you invoke any function. For example, this invocation returns a record of information about department number 10:

    department_pkg.get_dept_info(10);

    This invocation returns only the name of department number 10:

    department_pkg.get_dept_info(10).department_name;

    If the result for get_dept_info(10) is in the result cache, the result is returned from the cache; otherwise, the result is computed and added to the cache. Because get_dept_info depends on the DEPARTMENTS and EMPLOYEES tables, any committed change to DEPARTMENTS or EMPLOYEES invalidates all cached results forget_dept_inforelieving you of programming cache invalidation logic everywhere that DEPARTMENTS or EMPLOYEES might change.


  • 相关阅读:
    读写锁机制原理
    jvm
    (WPF) 再议binding:点击User Control时,User Control变换颜色或做其他的处理。
    (WF)
    (C# ) 解析XML。
    (C#) 调用执行批处理文件
    (WPF, Service) 删除注册表中的USB Enum值.
    (C#) 文件操作
    (C#) Parse xml 时, 返回的node值总是null。
    (PowerShell) Managing Windows Registry
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13316579.html
Copyright © 2020-2023  润新知