2016-09-19 137 views
-1

我試圖創建使用下面的查詢Oracle中的視圖中,執行它不允許數據定義操作,拋出錯誤消息綁定變量在oracle中

綁定變量不允許數據定義操作

當我在查詢窗口上運行相同的查詢它執行。試圖添加查看它會得到這個錯誤。

SELECT Dept.Name || ' ' || Course.DeptCode AS CourseCode, 'Yes' AS IsActive 
FROM Coursetab Course, Depttab dept 
WHERE  Course.CODE = Depttab.CODE 
UNION ALL 
SELECT Dept.OldName || ' ' || Course.oldDeptCode AS CourseCode, 'No' AS IsNotActive 
FROM Coursetab Course, Depttab dept 
WHERE  Course.OldCODE = Depttab.oldCODE 
+0

請提供您嘗試執行完整'CREATE VIEW'聲明。 – MJH

+0

我是Oracle的新手,我在View上右鍵添加新視圖,並在Select Query中給出了上述查詢。 –

+1

嘗試使用普通的sql來創建您的數據庫對象;創建一個視圖,看看[文檔](http://docs.oracle.com/database/121/SQLRF/statements_8004.htm#SQLRF01504) – Aleksej

回答

1

請參考下面如何創建一個視圖:

/* Created Tables */ 
CREATE TABLE Coursetab 
(
    DeptCode  NUMBER, 
    oldDeptCode NUMBER 
); 

CREATE TABLE Depttab 
(
    name  VARCHAR2 (10), 
    OldName VARCHAR2 (10), 
    CODE  NUMBER, 
    oldCODE NUMBER 
); 

/* Created Successfully view */ 
CREATE OR REPLACE VIEW XYX 
AS 
    (SELECT Dept.Name || ' ' || Course.DeptCode AS CourseCode, 
      'Yes' AS IsActive 
     FROM Coursetab Course, Depttab dept 
    WHERE Course.DeptCode = Dept.CODE 
    UNION ALL 
    SELECT Dept.OldName || ' ' || Course.oldDeptCode AS CourseCode, 
      'No' AS IsNotActive 
     FROM Coursetab Course, Depttab dept 
    WHERE Course.oldDeptCode = Dept.oldCODE);