【问题标题】:Interactive Grid - database constraint error handling for interactive grid交互式网格 - 交互式网格的数据库约束错误处理
【发布时间】:2020-05-18 16:30:55
【问题描述】:

我正在使用 APEX 19.2。我正在尝试使用错误处理函数来处理约束错误。

我在具有唯一约束的表上构建了一个交互式网格。我创建了constraint_lookup,将约束名称与消息匹配。

我创建了一个主要基于Oracle Doc示例的函数(例如在包wwv_flow_error_api中)

我唯一改变的是显示位置:

l_result.display_location := case
                                 when l_result.display_location =
                                      apex_error.c_on_error_page then
                                  apex_error.c_inline_with_field_and_notif
                                 else
                                  l_result.display_location
                               end;

现在,当我尝试添加具有非唯一值的值时,我在通知中收到一条我想要的消息,但我不知道如何处理它以在通知和字段中显示错误(例如在顶点验证中,您可以在其中关联项目)

我尝试列出所有 apex_error 属性,但我得到了

p_error
消息 ORA-00001:naruszono więzy unikatowe (#CONSTAINT_NAME#)
附加信息
ORA-00001:naruszono więzy unikatowe (#CONSTAINT_NAME#)
显示位置 ON_ERROR_PAGE
关联类型
页面项目名称
region_id
列别名
行数
model_instance_id
model_record_id
apex_error_code
原始消息
original_additional_info
ora_sqlcode -1
ora_sqlerrm ORA-00001: naruszono więzy unikatowe (#CONSTAINT_NAME#)
错误回溯
error_statement "ADM"

l_result
消息#错误消息#
Additional_info ORA-00001:naruszono wiezy unikatowe (#CONSTAINT_NAME#)
display_location INLINE_WITH_FIELD_AND_NOTIFICATION
页面项目名称
列别名

如何将约束中的字段与交互式网格中的字段连接起来?

【问题讨论】:

    标签: oracle-apex


    【解决方案1】:

    您应该添加 p_page_item_name 参数。例如:

        p_message  => 'Employee name cannot be null',
        p_display_location => apex_error.c_inline_with_field_and_notif ,
        p_page_item_name => 'P10_NAME');
    

    【讨论】:

    • 它不是交互式网格中的项目
    【解决方案2】:

    您能否使用以下代码更新您的错误处理功能。它添加了额外的调试语句。

    if p_error.ora_sqlcode in (-1, -2091, -2290, -2291, -2292) then
        l_constraint_name := apex_error.extract_constraint_name (
                                 p_error => p_error );
        apex_debug.info( 'Raised constraint error: %s', l_constraint_name );
    
        begin
            select message
              into l_result.message
              from constraint_lookup
             where constraint_name = l_constraint_name;
            apex_debug.info( 'Constraint found, new message: %s', l_result.message );
        exception when no_data_found then
            apex_debug.info( 'Constraint not found in constraint_lookup' );
        end;
    end if;
    

    在调试模式下运行您的应用程序并重现错误。之后,您可以使用 View Debug 来确定您的 constraint_lookup 条目是否实际被使用。

    【讨论】:

    • 但我知道我使用了哪一个 constraint_lookup 条目。我在 DB 中有 uq 约束,我使用错误处理函数处理错误消息,但我需要将其与交互式网格中的字段相关联,如顶点验证中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 2020-02-22
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多