开发者

Oracle- stored Proc

I'm writing a stored procedure. Please let me know if there is any good syntax to accomplish this:

I have three tables: table1, table2, table3.

I want to join table1 to table2 but if the primary key in table2 is zero, then I want to join table1 with table3.

Is there a way to conditionally do this in an Oracle Stored Procedure?

Code snippet is something like this:

select t1.col1,t2.colABC

from

table1 t1, table2 t2, table3 t3

Where

t1.colYear=Var_year

AND

t2.colID= " select (if t1.colGroup !=0 ,select t1.colGroup.

else 开发者_开发技巧 t3.colGroup)

TIA

-NewBee


Create two queries.

The first query should join table1 and table2 only where the primary key in table2 is not zero.

The second query should join table1 with table2 and table3 only where the primary key in table2 is zero.

Union the results of both queries together.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜