1

我写了一个内部连接语句。表已显示,但我无法从 EMPLOYEES_IMPORT 表中编辑全名

我的问题是......我应该如何创建一个可以编辑所有表格字段的有吸引力的表单?

请给我任何提示,否则我会发疯的:(

我试图创建一个视图:

CREATE VIEW STAMP_TEST AS
SELECT s.STAMP_ID ,
       s.PERSON_ID ,
       hp.FULL_NAME,
       h.DESCRIPTION
FROM STAMPS s
INNER JOIN EMPLOYEES_IMPORT hp ON s.PERSON_ID = hp.PERSON_ID
INNER JOIN DEPARTMENTS_IMPORT h ON hp.ORGANIZATION_ID = h.ORGANIZATION_ID

我想我不理解我的示例中的触发功能,因为我收到一个错误:

create or replace trigger trg_ed_seal_stamps
      instead of insert or update
      on STAMP_TEST
      for each row
    begin
      if inserting then
         insert into STAMPS (STAMP_ID, START_DT)
           values (:new.SEAL_STAMP_ID, :new.START_DT);
         insert into EMPLOYEES_IMPORT (FULL_NAME)
          values (:new.FULL_NAME);
         insert into DEPARTMENTS_IMPORT (DESCRIPTION)
           values (:new.DESCRIPTION);
     elsif updating then
        update STAMPS set
          STAMP_ID = :new.STAMP_ID
          where PERSON_ID = :new.PERSON_ID;
        update EMPLOYEES_IMPORT set
          FULL_NAME = :new.FULL_NAME
          where PERSON_ID = :new.PERSON_ID;
        update HDEPARTMENTS_IMPORT set
          DESCRIPTION = :new.DESCRIPTION
          where ORGANIZATION_ID = :new.ORGANIZATION_ID;
     end if;
   end;
  /

所以我设法创建了触发器,并且在 sql 语句中我可以更新值:)

但是当我用表格添加表格时,顶点仍然无法更新值

错误:

ORA-22816: unsupported feature with RETURNING clause

细节:

is_internal_error: false
component.type: APEX_APPLICATION_PAGE_PROCESS
component.id: 14401759410321665
component.name: Process form sds
error_backtrace:
----- PL/SQL Call Stack -----
  object      line  object
  handle    number  name
0x4255f33438       971  package body APEX_190100.WWV_FLOW_ERROR.INTERNAL_GET_ERROR
0x4255f33438      1039  package body APEX_190100.WWV_FLOW_ERROR.INTERNAL_ADD_ERROR
0x4255f33438      1092  package body APEX_190100.WWV_FLOW_ERROR.ADD_ERROR
0x40ffd4e4b0       593  package body APEX_190100.WWV_FLOW_PROCESS.ADD_ERROR_MESSAGE
0x4738108530       547  package body APEX_190100.WWV_FLOW_FORM_REGION.RAISE_ERROR_MESSAGE
0x4738108530      1185  package body APEX_190100.WWV_FLOW_FORM_REGION.DML_PROCESS_INT
0x4738108530      2198  package body APEX_190100.WWV_FLOW_FORM_REGION.DML_PROCESS
0x44b06ce5e8      1246  package body APEX_190100.WWV_FLOW_PROCESS_NATIVE.EXECUTE_PROCESS
0x448c6bff28      2473  package body APEX_190100.WWV_FLOW_PLUGIN.EXECUTE_PROCESS
0x40ffd4e4b0       203  package body APEX_190100.WWV_FLOW_PROCESS.PERFORM_PROCESS
0x40ffd4e4b0       450  package body APEX_190100.WWV_FLOW_PROCESS.PERFORM
0x472c9ca568      5726  package body APEX_190100.WWV_FLOW.ACCEPT
0x44b175fb00         2  anonymous block
4

1 回答 1

2

一种选择是根据您编写的语句创建一个视图。select然后创建一个INSTEAD OF触发器,该触发器将关注什么去哪里。所有这些都将在数据库中完成;Apex 将仅用于显示值 (IR) 并将数据“传输”到视图(表单),而代替触发器会将数据移动到适当的表中。


如何创建一个代替触发器?使用CREATE TRIGGER. 例如,基于 Scott 的模式:

这是一个视图:

SQL> create or replace view v_emp_dept as
  2  select d.deptno, d.dname, e.empno, e.ename, e.job, e.sal
  3  from emp e join dept d on e.deptno = d.deptno;

View created.

SQL> select * From v_emp_Dept;

    DEPTNO DNAME               EMPNO ENAME      JOB              SAL
---------- -------------- ---------- ---------- --------- ----------
        20 RESEARCH             7369 SMITH      CLERK            800
        30 SALES                7499 ALLEN      SALESMAN        1600
        30 SALES                7521 WARD       SALESMAN        1250
        20 RESEARCH             7566 JONES      MANAGER         2975
        30 SALES                7654 MARTIN     SALESMAN        1250
        30 SALES                7698 BLAKE      MANAGER         2850
        10 ACCOUNTING           7782 CLARK      MANAGER         2450
        20 RESEARCH             7788 SCOTT      ANALYST         3000
        10 ACCOUNTING           7839 KING       PRESIDENT       5000
        30 SALES                7844 TURNER     SALESMAN        1500
        20 RESEARCH             7876 ADAMS      CLERK           1100
        30 SALES                7900 JAMES      CLERK            950
        20 RESEARCH             7902 FORD       ANALYST         3000
        10 ACCOUNTING           7934 MILLER     CLERK           1300

14 rows selected.

SQL>

而不是触发器可能看起来像这样:

SQL> create or replace trigger trg_ed
  2    instead of insert or update
  3    on v_emp_dept
  4    for each row
  5  begin
  6    if inserting then
  7       insert into dept (deptno, dname)
  8         values (:new.deptno, :new.dname);
  9       insert into emp (deptno, empno, ename, job, sal)
 10         values (:new.deptno, :new.empno, :new.ename, :new.job, :new.sal);
 11    elsif updating then
 12       update dept set
 13         dname = :new.dname
 14         where deptno = :new.deptno;
 15       update emp set
 16         deptno = :new.deptno,
 17         ename = :new.ename,
 18         job = :new.job,
 19         sal = :new.sal
 20         where empno = :new.empno;
 21    end if;
 22  end;
 23  /

Trigger created.

SQL>

测试:更新和插入:

SQL> update v_emp_dept set
  2    dname = 'accounting'
  3    where deptno = 10;

3 rows updated.

SQL> insert into v_emp_dept (deptno, dname, empno, ename, job, sal)
  2    values (99, 'New dept', 1, 'Littlefoot', 'Developer', 1000);

1 row created.

结果:

SQL> select * From dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        99 New dept                              --> new row
        10 accounting     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> select * From emp;

     EMPNO ENAME      JOB              MGR HIREDATE        SAL       COMM     DEPTNO
---------- ---------- --------- ---------- -------- ---------- ---------- ----------
         1 Littlefoot Developer                           1000                    99 --> new row
      7369 SMITH      CLERK           7902 17.12.80        800                    20
      7499 ALLEN      SALESMAN        7698 20.02.81       1600        300         30
      7521 WARD       SALESMAN        7698 22.02.81       1250        500         30
      7566 JONES      MANAGER         7839 02.04.81       2975                    20
      7654 MARTIN     SALESMAN        7698 28.09.81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01.05.81       2850                    30
      7782 CLARK      MANAGER         7839 09.06.81       2450                    10
      7788 SCOTT      ANALYST         7566 09.12.82       3000                    20
      7839 KING       PRESIDENT            17.11.81       5000                    10
      7844 TURNER     SALESMAN        7698 08.09.81       1500          0         30
      7876 ADAMS      CLERK           7788 12.01.83       1100                    20
      7900 JAMES      CLERK           7698 03.12.81        950                    30
      7902 FORD       ANALYST         7566 03.12.81       3000                    20
      7934 MILLER     CLERK           7782 23.01.82       1300                    10

15 rows selected.

SQL>
于 2020-01-31T18:25:53.890 回答