<?xml version='1.0' encoding='UTF-8'?>
<ROWSET tableName='xxx'>
<EXEC_SQL>
CREATE OR REPLACE FUNCTION DYDIFF(
	DATE1   IN VARCHAR2  ,
	DATE2   IN VARCHAR2 := NULL ,
	PLUS    IN NUMBER   := 0 )
RETURN NUMBER
IS
    RTN     NUMBER(4);

BEGIN

	IF DATE2 IS NULL THEN
		RTN := TO_DATE( SUBSTRB(DATE1,1,8),'YYYYMMDD') - TRUNC(SYSDATE) + PLUS;
	ELSE
		RTN := TO_DATE( SUBSTRB(DATE1,1,8),'YYYYMMDD' ) - TO_DATE( SUBSTRB(DATE2,1,8),'YYYYMMDD' ) + PLUS;
	END IF;

	IF RTN &lt; 0 THEN RTN := 0; END IF;

	RETURN RTN;

END DYDIFF;
</EXEC_SQL>
</ROWSET>
