<?xml version='1.0' encoding='UTF-8'?>
<ROWSET tableName='xxx'>
<EXEC_SQL>
CREATE OR REPLACE FUNCTION WARN(
	XDYSTART   IN VARCHAR2 ,
	XDURATION  IN NUMBER   ,
	XCOMPLETE  IN NUMBER  )
RETURN VARCHAR2
IS
    RTN     VARCHAR2(1);
	COMP	NUMBER(5);

BEGIN
	COMP := TO_DATE( SUBSTRB(XDYSTART,1,8),'YYYYMMDD' ) - TRUNC(SYSDATE,'DD') ;

	IF COMP &gt; 0 OR XCOMPLETE = 100  THEN
		RTN := '0';
	ELSIF ( COMP + XDURATION ) &gt;= 0 AND XCOMPLETE &lt; 100 THEN
		RTN := '1';
	ELSIF ( COMP &lt; 0 AND XCOMPLETE = 0 ) OR
		   (( COMP + XDURATION ) &lt; 0 AND XCOMPLETE &lt; 100 ) THEN
		RTN := '2';
	END IF ;

	RETURN RTN;

END WARN;
</EXEC_SQL>
</ROWSET>
