2017-04-15 123 views
0

即時通訊有一個錯誤我現在很沮喪。我認爲由於這個錯誤,我還有另一個錯誤,在表中添加檢查約束時不能引用其他列。我必須在檢查約束中使用這個函數來比較結束時間。警告:函數創建編譯錯誤

1 create or replace function timing(dat in date, bran in varchar2(30), audi in number) 
    2 return number is time number 
    3 begin 
    4 select s_end into time from checking 
    5 where s_date=dat and branch=bran and a_id = audi; 
    6 return time; 
    7* end timing 
SQL>/

,我的表是

Name          Null? Type 
----------------------------------------- -------- ------------- 
S_ID          NOT NULL NUMBER 
M_ID            NUMBER 
A_ID            NUMBER 
S_DATE            DATE 
S_START           NUMBER 
S_END            NUMBER 
BRANCH            VARCHAR2(30) 

的錯誤是:

1/46 PLS-00103: Encountered the symbol "(" when expecting following: := .) , @ % default character The symbol ":=" was substituted for "(" to continue. 
3/1 PLS-00103: Encountered the symbol "BEGIN" when expecting the following: := . (@ % ; not null range default character 
The symbol ";" was substituted for "BEGIN" to continue. 
7/10 PLS-00103: Encountered the symbol "end-of-file" when expecting 
+0

'show errors'給你什麼? –

+0

1/46 PLS-00103:遇到符號「(」時出現以下情況: :=。),@%默認字符 符號「:=」代替「(」繼續。3/1 PLS-00103 :遇到符號「BEGIN」時預期 以下內容: :=。(@%;非空範圍默認字符 符號「;」代替「BEGIN」繼續 7/10 PLS-00103:遇到當期待@a_horse_with_no_name時,符號「end-of-file」 – user3828413

回答

2

您已經發布了同樣的問題在一個稍微不同的形式。我會以略微不同的形式在這裏回答。檢查約束不能引用用戶定義的函數。 Oracle不允許它,所以你的爭用「必須在檢查約束中使用這個函數」不能!

0

嘗試這樣

create or replace function timing(dat in date, bran in varchar2, audi in number) 
return number 
is 
time number; 
begin 
    select s_end into time 
    from checking 
    where s_date=dat and branch=bran 
    and a_id = audi; 
return time; 
end : 
/
+0

alter table checking添加約束chk check(s_start> timing(s_date,branch,a_id)) ERROR at line 1: ORA-00904:「TIMING」:invalid識別碼 – user3828413