Db2 SQL函数中的条件语句
我只想知道如何在函数中包含条件语句 例如,如果我执行以下操作Db2 SQL函数中的条件语句,db2,Db2,我只想知道如何在函数中包含条件语句 例如,如果我执行以下操作 select * from table(afunction(0)); select * from table(afunction(1)); 这两个语句将有不同的输出 我试过这个 create function afunction(custid int) returns table(customerid int) language sql reads sql data no external action determini
select * from table(afunction(0));
select * from table(afunction(1));
这两个语句将有不同的输出
我试过这个
create function afunction(custid int)
returns table(customerid int)
language sql
reads sql data
no external action
deterministic
return
if (custid = 0) then
select customerid from customer;
else
select customerid from orderdone;
end if;
但这导致了一个错误
我知道我可以打字
select customerid from customer;
select customerid from orderdone;
但我的动机是学习如何在函数中放置条件语句。我试过用case,但效果不太好。我的语法有什么问题?您需要:
作为将来的参考,“不起作用”不是一个问题描述。你看到了什么结果?还是看不见?你是不是收到了一个错误?哪一个?抱歉搞混了,我已经编辑了我的问题。谢谢你通知我。
create function ...
begin
if (custid = 0) then
return select customerid from customer;
else
return select customerid from orderdone;
end if;
end