简体   繁体   中英

Is it possible in from clause use case when statement

I am trying to do next query:

select * from (case when :p1 = '1' then t1 when :p1=2 then t2);

But it's not working. I assume that case when statement isn't allowed in from clause? Is there any other any way to resolve this. Thanks

No, you can't do that. The objects and identifiers have to be fixed when the query is parsed, so you can't bind those.

You could use a union with a check for the variable in each branch:

select * from t1
where :p1 = 1
union all 
select * from t2
where :p1 = 2;

assuming the structure of the tables is the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM