开发者

sql statement inside decode clause

开发者 https://www.devze.com 2023-02-14 22:19 出处:网络
The decode works like this: SELECT DECODE(\'col1\', \'x\', \'result1\',\'y\',\'result2\') resultFinal

The decode works like this:

SELECT DECODE('col1', 'x', 'result1','y','result2') resultFinal 
 FROM table1;

It possible to accomplish this in sql:

SELECT * 
  FROM (SELECT DECODE('col1', 'x' (someSql),'y',(someOthersql)) result 
          FROM table1)

So instead of result1 and result2 being fixed values, they would be sql statements. If not possible, h开发者_开发百科ow can I achieve the same result without a stored proc.

EDIT: someSql and someOthersql are both complex queries with many joins returining many but same number of cols with same col names.


If someSql and someOthersql return exactly one row with one column, then this should work.

The following works for me:

select decode(col, (select 'foo' from dual), (select 'bar' from dual))
from some table


I think you may need to create a PL/SQL procedure to handle the complex logic.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号