现在的位置: 首页 > 综合 > 正文

oracle中的exists

2013年11月06日 ⁄ 综合 ⁄ 共 464字 ⁄ 字号 评论关闭
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

 

抱歉!评论已关闭.