33.3 CURRENT_ROW_CHANGEDファンクション

このファンクションは、現在の行が2つのコンテキスト間で変更されたかどうかを判別します。値コンテキスト内の次の行を比較するには、両方のコンテキストに対してAPEX_EXEC.NEXT_ROWを使用します。

構文

API_PLUGIN_UTIL.CURRENT_ROW_CHANGED(
    p_old_row_context       IN wwv_flow_exec_api.t_context,
    p_new_row_context       IN wwv_flow_exec_api.t_context )
RETURN BOOLEAN;

パラメータ

表33-3 CURRENT_ROW_CHANGEDのパラメータ

パラメータ 説明
p_old_row_context 変更前の値を含む値コンテキスト
p_new_row_context 変更後の値を含む値コンテキスト

戻り値

表33-4 CURRENT_ROW_CHANGEDの戻り値

パラメータ 説明
* 行間に差異があるかどうか。

次の例では、更新する特定の行に対してプラグインDMLファンクション内で再フェッチ操作を実行し、その行がDML操作で実際に変更されるかどうかを確認します。そうでない場合は、HTTPリクエストを抑止できます。

procedure plugin_dml(
    p_plugin     in            apex_plugin.t_plugin,
    p_web_source in            apex_plugin.t_web_source,
    p_params     in            apex_plugin.t_web_source_dml_params,
    p_result     in out nocopy apex_plugin.t_web_source_dml_result )
IS
    l_web_source_operation apex_plugin.t_web_source_operation;
    l_request_body         clob;
    l_response             clob;

    l_refetch_context      apex_exec.t_context;
    l_checksum             varchar2(32767);
    l_refetched_checksum   varchar2(32767);

BEGIN
    p_result.update_values_context := p_params.update_values_context;

    --
    -- this code performs a "refetch" operation for a row, in order to perform
    -- lost update detection. This happens before the actual DML.
    --
    IF p_web_source.operations.exists( apex_plugin.c_db_operation_fetch_row ) THEN

        l_web_source_operation := apex_plugin_util.get_web_source_operation(
            p_web_source       => p_web_source,
            p_db_operation     => wwv_flow_plugin_api.c_db_operation_fetch_row,
            p_preserve_headers => false,
            p_perform_init     => true );

        -- add some logic to add primary key values to the URL or as HTTP headers here
        -- PK values can be obtained from "p_params.update_values_context"

        wwv_flow_plugin_util.make_rest_request(
            p_web_source_operation => l_web_source_operation,
            p_request_body         => l_request_body,
            p_response             => l_response,
            p_response_parameters  => p_result.out_parameters );

        l_refetch_context := wwv_flow_plugin_util.parse_refetch_response(
            p_web_source_operation => l_web_source_operation,
            p_web_source           => p_web_source,
            p_response             => l_response,
            p_values_context       => p_params.update_values_context );

        IF apex_plugin_util.current_row_changed(
               p_old_row_context   => l_refetch_context,
               p_new_row_context   => p_params.update_values_context )
        THEN
            -- perform actual DML here
            --
        ELSE
            apex_exec.set_row_status(
                p_context  => p_result.update_values_context,
                p_sqlcode  => 0,
                p_sqlerrm  => 'SKIPPED' );
        END IF;
    END IF;
END plugin_dml;