oracle中的exists不能像MSSQL中似的可以写if exists(),按参考手册所讲:
An
例如:
An
EXISTS
condition tests for existence of rows in a subquery.只能用在自查询中.例如:
SELECT department_id
FROM departments d
WHERE EXISTS
(SELECT * FROM employees e
WHERE d.department_id
= e.department_id);
FROM departments d
WHERE EXISTS
(SELECT * FROM employees e
WHERE d.department_id
= e.department_id);
如果想实现像MSSQL中的if exists的功能,可以如下实现:
declare
a int;
begin
select count(*) into a from test_table;
if a > 0 then -- 变相的为if exists
begin
DBMS_OUTPUT.put_line('测试exists');
end;
end if;
end
a int;
begin
select count(*) into a from test_table;
if a > 0 then -- 变相的为if exists
begin
DBMS_OUTPUT.put_line('测试exists');
end;
end if;
end