2014-05-12 40 views
0

我正在使用Oracle PL/SQL。 我寫了下面的程序:如果在oracle中有更新和計數器的條件

Declare result number; 
     countExceed Number; 
begin 
select count(*) into result from 
    (select "LoginName","LoginPassword" from "ApplicationUser" where "LoginName"='adin' and "LoginPassword"='admin'); 
if result>0 
then 
execute immediate('Update "test" set "Count"=0 where "Count"<5'); 
dbms_output.put_line('Update as count 0!'); 
elsif result=0 then 
execute immediate(' select "Count" 
        into countExceed from "test"; 
        if countExceed >5 then 
       Update "test" set "Count"="Count"+1 where "Count" <5; 
        END IF;'); 
dbms_output.put_line('Update as Count + 1!'); 
End If; 
end; 

所有我希望它做的是:

檢查用戶名和密碼,如果存在檢查計< = 5,如果爲真更新計數= 0其中username =」管理員。 如果用戶名和密碼存在,並且計數> 5,則更新Isactive = 0。如果用戶名和密碼不存在,最後 update count = count + 1其中username = username。

上面的程序給我這個錯誤

ORA-00911:無效字符 請幫助。

+0

問題是什麼?或錯誤?或問題? – i100

+0

對不起。編輯.. –

回答

1

試試這個

Declare result number; 
     countExceed Number; 
begin 
    select count(*) into result from ApplicationUser where LoginName='adin' and LoginPassword='admin'; 
    if result>0 then 
    execute immediate('Update "test" set "Count"=0 where "Count"<5'); 
    dbms_output.put_line('Update as count 0!'); 
    else 
     select "Count" into countExceed from "test"; 
     if countExceed >5 then 
     execute immediate('Update "test" set "Count"="Count"+1 where "Count" <5'); 
    END IF; 
    dbms_output.put_line('Update as Count + 1!'); 
    End If; 
end; 
+0

ORA-01422:確切的獲取返回超過請求的行數 –

+0

我的錯誤...作品像魅力!非常感謝!! –