orcle函数的使用,及其调用
CREATE OR REPLACE Function getBdateT(
D_Build date,
Q_Date date
) return Date as
D_Return Date; /*返回的日期*/
Q_Year int := 1;/*查询日期的年份*/
Q_Quartar int := 1;/*查询日期的季度*/
D_Year int := 1;/*成立日期的年份*/
D_Quartar int := 1;/*成立日期的季度*/
begin
/* 赋初始值*/
D_Return := sysdate;
select extract(year from Q_Date) into Q_Year from dual ;
select extract(year from D_Build) into D_Year from dual ;
select TO_NUMBER(TO_CHAR(Q_Date,'Q')) into Q_Quartar from dual ;
select TO_NUMBER(TO_CHAR(D_Build,'Q')) into D_Quartar from dual ;
if (Q_Year = D_Year AND D_Quartar =Q_Quartar) then
D_Return := D_Build;
else
D_Return := Q_Date;
end if;
return D_Return;
end;
-------------------------------------------------------------------------
函数的调用
select getBdateT(date'2016-05-01',date'2016-05-04') from dual
select * from ta ,t_p_ab_port t1 where ta. c_pot_code = t1.c_port_code and ta.c_Port_code in (sdfsdf) and ta.rq in (cxrq , getBdateT(t1.d_build,cxrq) )