2014-10-31 86 views
0

我有一個從選擇查詢調用的函數,下面是完美的函數。我想打電話給下面的步驟,如果布爾= 1是將值插入登錄表:從函數PLSQL調用過程

create or replace FUNCTION isLoggedIn(x IN VARCHAR2, y IN VARCHAR2) 
RETURN number IS 
boolean number(1) := 0; 
BEGIN 
SELECT count(*) into boolean 
FROM VIEWLOGIN 
WHERE username = x AND password = y; 

IF boolean = 1 THEN 
    PROCDURELOGIN 
    RETURN boolean;  
ELSE 
    RETURN 0; 
END IF; 
END; 

這是我的程序:

create or replace PROCEDURE PROCDURELOGIN 
IS 
BEGIN 
    INSERT INTO "SW3"."LOGIN" (LOGINID, MEMBERID) 
    VALUES (seqLogin.NEXTVAL, '1'); 
    Commit; 
END; 

Create view VIEWLOGIN 
SELECT firstname, surname, username, password 
FROM member 

但我得到的錯誤,當我運行查詢:

Error starting at line : 1 in command - 
SELECT firstname, surname, isLoggedIn(username, password) 
FROM VIEWLOGIN 
WHERE username = 'fionawalshe' AND password = 'qwertyu8' 
Error report - 
SQL Error: ORA-14551: cannot perform a DML operation inside a query 
ORA-06512: at "SW3.PROCDURELOGIN", line 4 
ORA-06512: at "SW3.ISLOGGEDIN", line 10 
14551. 00000 - "cannot perform a DML operation inside a query " 
*Cause: DML operation like insert, update, delete or select-for-update 
      cannot be performed inside a query or under a PDML slave. 
*Action: Ensure that the offending DML operation is not performed or 
      use an autonomous transaction to perform the DML operation within 
      the query or PDML slave. 
+1

所以叫它。什麼是問題? – OldProgrammer 2014-10-31 22:14:14

+0

請編輯您的問題並添加VIEWLOGIN視圖的來源。謝謝。 – 2014-10-31 22:22:07

回答

2

Oracle在錯誤信息中明確表示,什麼是問題。試試這個:

create or replace PROCEDURE PROCDURELOGIN 
IS 
pragma autonomous_transaction; 
BEGIN 
    INSERT INTO "SW3"."LOGIN" (LOGINID, MEMBERID) 
    VALUES (seqLogin.NEXTVAL, '1'); 
    Commit; 
END; 

順便說一下,我不喜歡這樣的程序,並建議不要使用它們,如果可能的話。

+0

完美分類。 – 2014-10-31 23:27:19