我的语句如下,用select for update获取行锁用于后续操作。declare lastid decimal;
beginSELECT step_id into lastid FROM table where step_id=1 for update;
commit;
end;
正常情况没有问题,但如果where条件不满足,那么会抛no data found的异常。如果改成下面这样,看似可以执行,实际上并没有锁定table表,所以也是不行的。
select nvl((SELECT step_id FROM Table where step_id=1),null) into lastid from dual for update;
不知道应该如何修改此语句?
beginSELECT step_id into lastid FROM table where step_id=1 for update;
commit;
end;
正常情况没有问题,但如果where条件不满足,那么会抛no data found的异常。如果改成下面这样,看似可以执行,实际上并没有锁定table表,所以也是不行的。
select nvl((SELECT step_id FROM Table where step_id=1),null) into lastid from dual for update;
不知道应该如何修改此语句?
declare lastid decimal;
row number:=0;
begin
select count(1) into row from mytable where step_id=1;
if row<>0 then
SELECT step_id into lastid FROM mytable where step_id=1 for update;
commit;
end if;
end;
/
lastid decimal;
begin
SELECT step_id into lastid FROM table where step_id=1 for update;
EXCEPTION WHEN No_Data_Found THEN
NULL;
commit;
end;话说,where条件查不到资料的时候,你也要锁表吗?..