【问题标题】:if else condition in oracle with update and counter in itif else 条件在 oracle 中,其中包含更新和计数器
【发布时间】:2014-05-12 19:51:42
【问题描述】:

我正在使用 Oracle、PL/SQL。 我写了以下程序:

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,则更新 Isactive=0。最后 如果用户名和密码不存在,更新 count=count+1 where username=username.

上面的程序给了我这个错误

ORA-00911: 无效字符 请帮忙。

【问题讨论】:

  • 问题是什么?还是错误?还是问题?

标签: oracle plsql


【解决方案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;

【讨论】:

  • ORA-01422:精确提取返回的行数超过了请求的行数
猜你喜欢
  • 2015-09-06
  • 1970-01-01
  • 2012-12-11
  • 1970-01-01
  • 2020-07-17
  • 1970-01-01
  • 2021-11-14
  • 2019-11-21
  • 1970-01-01
相关资源
最近更新 更多