在oracle apex中,当我修改具有联合查询的交互式网格中的数据时,它给出了ORA-02014错误。如何处理这个错误?

问题描述 投票:0回答:1

当我尝试修改交互式网格列时,出现 ORA-02014 错误。

在后端,我使用了带有 union 的 sql 查询,还使用 join 来连接 3 个表。

我在过去几天尝试过,我希望有人能找到解决方案。

oracle-apex union interactive-grid ora-02014
1个回答
0
投票

除了我建议的选项之外,可能还有其他选项 - 例如

  • 重写查询,这样您就不会连接表,而是通过函数获取lookup值,然后将这些列设置为只读,以便更新不会影响它们,或者

  • 您可以(在 Apex 中)使用以下设置创建自己的流程,例如此流程(有关更多示例代码,请参阅“帮助”):


我更喜欢创建一个视图而不是处理更新的触发器。

这是一个例子;看看是否有帮助。

连接一些表并包含

union
(这就是您所描述的)的视图:

SQL> create or replace view v_emp_dept as
  2  select distinct d.deptno, d.dname, e.empno, e.ename, e.job
  3     from emp e join dept d on e.deptno = d.deptno
  4     where e.deptno = 10
  5  union all
  6  select distinct d.deptno, d.dname, e.empno, e.ename, e.job
  7     from emp e join dept d on e.deptno = d.deptno
  8     where e.deptno = 20;

View created.

这是一行:

SQL> select * from v_emp_dept where empno = 7369;

    DEPTNO DNAME               EMPNO ENAME      JOB
---------- -------------- ---------- ---------- ---------
        20 RESEARCH             7369 SMITH      CLERK

如果我们尝试更新会发生什么?失败(虽然不是因为你的错误,但是 - 它失败了):

SQL> update v_emp_dept set deptno = 10 where empno = 7369;
update v_emp_dept set deptno = 10 where empno = 7369
       *
ERROR at line 1:
ORA-01732: data manipulation operation not legal on this view

替代触发器:

SQL> create or replace trigger trg_ed
  2    instead of update
  3    on v_emp_dept
  4  begin
  5    update emp e set
  6      e.deptno = :new.deptno
  7      where e.empno = :new.empno;
  8  end;
  9  /

Trigger created.

重新运行相同的

update
语句:

SQL> update v_emp_dept set deptno = 10 where empno = 7369;

1 row updated.

对;现在它可以工作并更新值 - 不是在视图中(它只是反映该更改),而是在基础表中:

SQL> select * from v_emp_dept where empno = 7369;

    DEPTNO DNAME               EMPNO ENAME      JOB
---------- -------------- ---------- ---------- ---------
        10 ACCOUNTING           7369 SMITH      CLERK

SQL> select deptno from emp where empno = 7369;

    DEPTNO
----------
        10

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.