· 8 years ago · Dec 14, 2017, 02:52 AM
1if ((select *
2 from table1
3 where quant>1000) is not null)
4then ...
5else RAISE error$e;
6end if;
7
8if exists (select *
9 from table1
10 where quant>1000)
11
12create table table1 (quant number);
13insert into table1 values (0);
14
15declare
16 function existsHighQuant return boolean is
17 begin
18 for r in (select 1 from table1 where quant>1000) loop return true; end loop; return false;
19 end;
20 -- или так - не очень изÑщный по моему мнению вариант
21 function existsRow(stmt varchar2) return boolean is
22 curs sys_refcursor;
23 dummy number;
24 begin
25 open curs for stmt; fetch curs into dummy; return curs%found;
26 end;
27begin
28 if existsHighQuant then
29 null; --do something
30 else
31 raise_application_error(-20000, 'quant gt 1000 not found');
32 end if;
33
34 if existsRow('select 1 from table1') then dbms_output.put_line('at least 1 row exists'); end if;
35end;
36/
37
38ORA-20000: quant gt 1000 not found
39
40insert into table1 values (2000);
41-- повторить вызов блока
42
43PL/SQL procedure successfully completed.
44at least 1 row exists