开发者

sql statement inside decode clause

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜