码迷,mamicode.com
首页 > 其他好文 > 详细

orcle函数的使用,及其调用

时间:2016-12-13 10:07:59      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:where   nbsp   number   har   ret   port   and   into   return   

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) )

 

orcle函数的使用,及其调用

标签:where   nbsp   number   har   ret   port   and   into   return   

原文地址:http://www.cnblogs.com/wglwgl/p/6168564.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!