You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle Forms按钮触发后无法高亮指定列值问题求助

Oracle Forms 搜索高亮无效果问题排查与解决

问题场景

在Oracle Forms中通过游标加载员工与部门数据,点击搜索按钮后希望高亮以特定字母/单词开头的ename列值,已创建视觉属性VA,代码编译无错误但运行时无高亮效果。

原数据获取代码

declare
    cursor emp_cur is
                select e.employee_id,e.last_name,e.salary,e.hire_date,e.department_id,d.department_name
                from employees e,departments d
                where e.department_id=d.department_id and e.department_id = :dept.deptid;

begin
        first_record;
   for i in emp_cur
            loop
         :emp.empid := i.employee_id;
         :emp.ename := i.last_name;
         :emp.sal := i.salary;
         :emp.hire_date := i.hire_date;
         :emp.deptid := i.department_id;
         :emp.dname := i.department_name;
            next_record;
            end loop;
end;

原搜索高亮代码

go_block('emp');
begin
loop
    first_record;
        if lower(:emp.ename) like :emp.txt_search||'%' then
            set_item_instance_property('emp.ename',current_record,visual_attribute,'VA');
            else
                    if :system.last_record = 'TRUE' THEN
                exit;
                    else next_record;
            end if;
        end if;
end loop;
go_item('txt_search');
end;

问题原因

  1. 循环遍历逻辑错误:每次循环都调用first_record,导致永远只检查第一条记录,无法遍历所有加载的记录。
  2. 匹配后未跳转记录:当找到匹配记录设置高亮后,没有执行next_record,会卡在当前记录进入死循环。
  3. 未重置视觉属性:如果之前搜索有高亮过记录,新搜索时未将这些记录的属性恢复默认,可能导致显示异常。
  4. 大小写匹配不统一:仅将:emp.ename转小写,但:emp.txt_search未转小写,若输入大写字母会导致匹配失败。

解决方法

针对上述问题,修改搜索高亮代码如下:

go_block('emp');
first_record; -- 先回到第一条记录
begin
    loop
        -- 先重置当前记录的视觉属性为默认
        set_item_instance_property('emp.ename', current_record, visual_attribute, null);
        
        -- 统一大小写进行匹配
        if lower(:emp.ename) like lower(:emp.txt_search) || '%' then
            set_item_instance_property('emp.ename', current_record, visual_attribute, 'VA');
        end if;
        
        -- 判断是否为最后一条记录,是则退出循环,否则跳转下一条
        if :system.last_record = 'TRUE' then
            exit;
        else
            next_record;
        end if;
    end loop;
    go_item('txt_search');
end;

额外检查项

  • 确认视觉属性VA已正确设置(比如设置了区别于默认的背景色或前景色,确保视觉上能看出高亮效果)。
  • 确认数据块emp已正确加载所有游标返回的记录(可在加载后检查记录总数是否符合预期)。

内容的提问来源于stack exchange,提问作者Navjot Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 14:45:59