实现功能:如果表2为空就查表一,否则查询表1
if exists (select 0 from table2)
select * from table 1
else
select * from table 2
这样的语句实现不了,在oracle中该怎么写

解决方案 »

  1.   

    贴子发重复了declare v_count int;
    begin
    select count(*) into v_count from t1;if v_count > 0 then
    语句1
    else
    语句2
    end if;
    end;
      

  2.   

    可以使用存储过程来判断declare number int
    begin
    select count(*)number from 表2if number>0 then
    select * from 表2
    else
    select * from 表1
    end if
    end
      

  3.   

    declare v_count int;
    begin
    select count(*) into v_count from t1;if v_count > 0 then
    语句1
    else
    语句2
    end if;
    end;
    -----------------------------------转载楼上