我有一個錯字視圖編輯列:我如何能在現有的視圖
CREATE OR REPLACE VIEW "USER"."VW_X" AS (
SELECT id,
name,
decode(WRONG_COLUMN, 1, 'T', 0, 'F') AS problem
FROM "USER"."TEST");
對於使用
CREATE OR REPLACE VIEW "USER"."VW_X" AS (
SELECT id,
name,
decode(RIGHT_COLUMN, 1, 'T', 0, 'F') AS problem
FROM "USER"."TEST");
結果下面的消息在一些原因:
Error starting at line : 5 in command - CREATE OR REPLACE VIEW "USER"."VW_X" AS ( SELECT id, name, decode(RIGHT_COLUMN, 1, 'T', 0, 'F') AS problem FROM "USER"."TEST") Error report - SQL Error: ORA-02449: unique/primary keys in table referenced by foreign keys 02449. 00000 - "unique/primary keys in table referenced by foreign keys" *Cause: An attempt was made to drop a table with unique or primary keys referenced by foreign keys in another table. *Action: Before performing the above operations the table, drop the foreign key constraints in other tables. You can see what constraints are referencing a table by issuing the following command: SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = "tabnam";
我甚至不知道,一個觀點是一個參考的有效目標。因此,這裏的問題:
SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = "USER"."VW_X";
回報什麼,這一點:
SELECT a.table_name,
a.column_name,
a.constraint_name,
c.owner,
c.r_owner,
c_pk.table_name r_table_name,
c_pk.constraint_name r_pk,
c.status
FROM all_cons_columns a
JOIN all_constraints c
ON a.owner = c.owner AND a.constraint_name = c.constraint_name
JOIN all_constraints c_pk
ON c.r_owner = c_pk.owner AND c.r_constraint_name = c_pk.constraint_name
WHERE c_pk.table_name = 'VW_X' or c.table_name = 'VW_X';
(一個在頂部答案this後變體) 返回所有這四個約束與'DISABLED'
狀態。
我特地到ALTER VIEW
(這個名字聽起來相當有希望的),但它似乎沒有什麼我要找的。
有什麼建議嗎?
注:這是可能可能有在所提供的示例代碼中的一些語法錯誤。這些都是樣機,在簡單的利益,出於職業偏執,大約有十幾個不相關的列已被刪除,名稱已被更改。
編輯: 這是Oracle11g的
編輯: 我找到的解決方案是
-- drop view.
DROP VIEW "USER"."VW_X" CASCADE CONSTRAINTS;
commit;
-- create view.
CREATE OR REPLACE VIEW "USER"."VW_X" AS (
SELECT id,
name,
decode(RIGHT_COLUMN, 1, 'T', 0, 'F') AS problem
FROM "USER"."TEST");
commit;
CASCADE CONSTRAINTS
似乎是缺少的環節。我很確定這些限制已經消失,但我並不特別在意。
我沒有用FK對意見的解決方案。但是,看起來行爲與表格類似。你將需要確定FK約束你的觀點,刪除它們,改變你的看法,然後重新創建約束。您將無法在單個alter view語句中執行此操作。 – unleashed