oracle中的exists

来源:互联网 发布:娇喘恶搞软件下载 编辑:程序博客网 时间:2024/05/21 04:18
oracle中的exists不能像MSSQL中似的可以写if exists(),按参考手册所讲:
    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);

如果想实现像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

 
原创粉丝点击