ORA-01779 canon修改映射到非密钥保留表的列

时间:2013-06-06 09:33:40

标签: sql oracle insert insert-update

create or replace view cv_vallist_all as
select
  S.BRN_ID,
  S.CODE,
  S.CONSTVAL,
  S.GENMODE,
  S.CONSTCODE,
  substr (nvl(L.SHORTNAME,S.SHORTNAME), 1, 10) as SHORTNAME,
  S.ARCFL,
  substr (nvl(L.NAME,S.NAME), 1, 30) as NAME,
  substr (nvl(L.PRIM,S.PRIM), 1, 250) as PRIM,
  substr (nvl(L.LONGNAME,S.LONGNAME), 1, 250) as LONGNAME,
  S.TXT_ADD
from C_VALLIST_LNG L,
     C_VALLIST_STD S
where L.LNG_ID(+) = P_Lng
  and L.BRN_ID(+) = S.BRN_ID
  and L.CODE(+) = S.CODE
  and L.CONSTVAL(+) = S.CONSTVAL;
comment on column CV_VALLIST_ALL.CODE is 'CODE';
comment on column CV_VALLIST_ALL.CONSTVAL is 'CONSTVAL';
comment on column CV_VALLIST_ALL.GENMODE is 'GENMODE';
comment on column CV_VALLIST_ALL.CONSTCODE is 'CONSTCODE';
comment on column CV_VALLIST_ALL.SHORTNAME is 'SHORTNAME';
comment on column CV_VALLIST_ALL.ARCFL is 'ARCFL';
comment on column CV_VALLIST_ALL.NAME is 'NAME';
comment on column CV_VALLIST_ALL.PRIM is 'PRIM';
comment on column CV_VALLIST_ALL.LONGNAME is 'LONGNAME';
comment on column CV_VALLIST_ALL.TXT_ADD is 'TXT_ADD';
insert into CV_VALLIST_ALL
  (CODE, CONSTVAL, BRN_ID, GENMODE, CONSTCODE, SHORTNAME, ARCFL, NAME, PRIM, LONGNAME, TXT_ADD)
values
  ('N_FRM_REF', 't', 21, 'n', '', 'T', 0, 't', '', 't', '')

2 个答案:

答案 0 :(得分:4)

列SHORTNAME在您的视图中定义为substr (nvl(L.SHORTNAME,S.SHORTNAME), 1, 10)。显然,您不能简单地在该列中插入值。同样,其他列也不适合简单插入。

您可以在视图上定义INSTEAD OF触发器,以执行表C_VALLIST_STD和C_VALLIST_LNG中的所需插入。

答案 1 :(得分:0)

CREATE TABLE tab1(id NUMBER, col1 NUMBER);
-- table TAB1 created.
CREATE TABLE tab2(id NUMBER, col1 NUMBER, col2 NUMBER, col3 NUMBER);
-- table TAB2 created.

INSERT  ALL
INTO tab1(id, col1)             VALUES (tab1_id, tab1_col1)
INTO tab2(id, col1, col2, col3) VALUES (tab2_id, tab2_col1, tab2_col2, tab2_col3)
SELECT  1  AS tab1_id
,       11 AS tab1_col1
,       1  AS tab2_id
,       21 AS tab2_col1
,       22 AS tab2_col2
,       23 AS tab2_col3
FROM    DUAL
;
-- 2 rows inserted.

SELECT * FROM tab1;
-- 1    11

SELECT * FROM tab2;
-- 1    21  22  23

CREATE  VIEW tab_vw AS
SELECT  tab1.id   AS tab1_id
,       tab1.col1 AS tab1_col1
,       tab2.id   AS tab2_id
,       tab2.col1 AS tab2_col1
,       tab2.col2 AS tab2_col2
,       tab2.col3 AS tab2_col3
FROM    tab1
JOIN    tab2
ON      tab1.id = tab2.id
;
-- view TAB_VW created.

SELECT * FROM tab_vw;
-- 1    11  1   21  22  23

CREATE OR REPLACE TRIGGER tab_trg
INSTEAD OF INSERT ON tab_vw
FOR EACH ROW
BEGIN
    INSERT INTO tab1(id, col1)             VALUES (:new.tab1_id, :new.tab1_col1);
    INSERT INTO tab2(id, col1, col2, col3) VALUES (:new.tab2_id, :new.tab2_col1, :new.tab2_col2, :new.tab2_col3);
END;
-- TRIGGER TAB_TRG compiled

INSERT  INTO tab_vw
(
        tab1_id
,       tab1_col1
,       tab2_id
,       tab2_col1
,       tab2_col2
,       tab2_col3
)
SELECT  2  AS tab1_id
,       11 AS tab1_col1
,       2  AS tab2_id
,       21 AS tab2_col1
,       22 AS tab2_col2
,       23 AS tab2_col3
FROM    DUAL
;
-- 1 rows inserted.

SELECT  *
FROM    tab_vw;
-- 1    11  1   21  22  23
-- 2    11  2   21  22  23