如果表1存在id=1,執行:select * from 表1,否則執行:select * from 表2
Oracle要怎么寫呢?
表1和表2結構一樣,只是內容不一樣
uj5u.com熱心網友回復:
-- 可以寫成這樣,但是建議你分兩步寫比較好。select * from t1 where id = 1
union all
select * from t2 where not exists(select * from t1 where id =1)
uj5u.com熱心網友回復:
declarev_cnt int;
begin
select count(1) into v_cnt from 表1 where id=1 and rownum<2;
if v_cnt>0 then
select * from 表1
else
select * from 表2
end if;
end;
大概這樣吧,隨手寫的,沒校對具體語法。
uj5u.com熱心網友回復:
SELECTCASE
WHEN rowcount > 0 THEN
select *
from 表1
ELSE
SELECT *
FROM 表2
END
FROM (
SELECT count(*) rowcount
FROM 表1
WHERE id=1 ) a
uj5u.com熱心網友回復:
采用存盤程序實作,支持3樓uj5u.com熱心網友回復:
select*from tab1 where exists(select*from tab1 t1 where t1.id = 1)union all
select*from tab2 where not exists(select*from tab1 t2 where t2.id = 1)
uj5u.com熱心網友回復:
select * from a1 where exists (select null from dual where a1.id=1)union all
select * from a2 where not exists(select null from a1 where a1.id=1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/36510.html
標籤:基礎和管理
上一篇:關于oracle權限查詢
