Wednesday, December 16, 2020

Select Function in Oracle Pl/Sql

create or replace function f_company_address(p_company varchar2) 
return Char 
is
v varchar2(200);
begin

select address  into v
from ifsapp.company_address_tab
where address_id='1LBGH'
and company=p_company;
return(v);
end;


select f_company_address('GTY') , f_company_address('GAT' ) from dual




CREATE OR REPLACE function IFSINFO.f_company_address(p_company varchar2) 
    return Char 
is
    v varchar2(200);
begin
    if p_company='GTY' then 
        select      address  into v
        from        ifsapp.company_address_tab
        where       address_id='1LBGH'
        and         company=p_company;
    elsif p_company='GAT' then 
        select      address  into v
        from        ifsapp.company_address_tab
        where       address_id='2RUPS'
        and         company=p_company;
    end if;
return(v);
    
end;
/


-------------------------
CREATE OR REPLACE FUNCTION IFSAPP.X_GET_GAT_START_DATE ( P_DATE DATE,P_COMPANY VARCHAR2) RETURN DATE

IS 
V DATE;

BEGIN


NULL;

IF UPPER(P_COMPANY)='GAT' THEN 
IF   TO_CHAR(P_DATE,'DD') BETWEEN 16 AND 31 THEN 

 SELECT TRUNC(TO_DATE(P_DATE,'DD-MON-RR'),'MON')+15 INTO V FROM DUAL;
 
ELSE 

SELECT ADD_MONTHS(TRUNC(TO_DATE(P_DATE,'DD-MON-RR'),'MON')+15,-1) INTO V FROM DUAL; 

END IF;

ELSE 

    SELECT TO_CHAR(TRUNC(TO_DATE(P_DATE,'DD-MON-RR') ,'MONTH'),'DD-MON-RRRR') INTO V FROM DUAL;

END IF ;


RETURN V;


END;
/


CREATE OR REPLACE FUNCTION IFSAPP.x_get_gat_end_date ( p_date date ) return date


is 
v date;




begin


null;


if  to_char(p_date,'dd') between 01 and 15 then 


 SELECT (TRUNC(TO_DATE(P_DATE,'DD-MON-RR'),'MON')+15)-1 INTO V FROM DUAL;
 

else 


 SELECT ADD_MONTHS(TRUNC(TO_DATE(P_DATE,'DD-MON-RR'),'MON')+14,+1) INTO V FROM DUAL;
 
 

end if;






return v;




end;
/

No comments:

Post a Comment

How to install and configure Oracle Apex 24.1 with ORDS 22, Tomcat 9 and Jasper Report 7 on Oracle Linux 8.10

#########################Install Oracle  APEX 24.1################################ ----------------------------------------------------...