- 论坛徽章:
- 1
|
回复 #13 doni 的帖子
pl/sql不能直接这么写的,select colid from tbl2 where colid = 4; 要写成select colid into some_variable from tbl2 where colid;
- begin
- insert into tbl1 values('3', 'abc3');
- declare
- l_var varchar2(20);
- begin
- select colid into l_var from tbl2
- where colid = 4;
- exception
- when no_data_found then
- insert into tbl2 values('4', 'def4');
- end;
- end;
复制代码
我觉得和11楼说的那样,不用嵌套块的话也可以用count来做:
- declare
- l_cnt number;
- begin
- insert into tbl1 values('3', 'abc3');
- select count(colid) into l_cnt from tbl2 where colid='4';
- if l_cnt=0 then
- insert into tbl2 values('4','def4');
- end if;
- end;
复制代码
[ 本帖最后由 Minsic 于 2009-9-11 10:22 编辑 ] |
|