CREATE OR REPLACE FUNCTION MOUMI.SP_CM_DEC_FU(INSTR IN VARCHAR)
  RETURN VARCHAR2
IS
  Result VARCHAR(32);
  BEGIN
    SELECT NAME INTO Result
    FROM MOUMI_MUSER
    WHERE NAME = INSTR AND ROWNUM=1 ;
  RETURN(Result);
  END SP_CM_DEC_FU;
/

CREATE FUNCTION SP_CM_ENC_FU(INSTR VARCHAR(1000))
  RETURNS VARCHAR(1000)
  DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL
  BEGIN ATOMIC
  RETURN 'ENCRYPTED - ' || INSTR;
END
/


/* 전체자료 카운트  */
CREATE OR REPLACE FUNCTION FN_ALLCNT ( DC_ID IN VARCHAR )
  RETURN VARCHAR2  
IS
Result varchar(20);
begin
SELECT COUNT(*)  INTO Result
FROM MOUMI_TOT_REPORT RT, MOUMI_TOT_DOC DC  
WHERE  RT.DOC_ID = dc_id 
AND RT.DOC_ID = DC.ID
AND RT.DEL_TYPE = 'N';
return(Result);
end FN_ALLCNT;
/

/* 자료회수 카운트  */
CREATE OR REPLACE FUNCTION FN_NOTECNT ( DC_ID IN VARCHAR )
  RETURN VARCHAR2  
IS
Result VARCHAR(20);
begin
SELECT COUNT(*)  INTO Result
FROM MOUMI_TOT_REPORT RT, MOUMI_TOT_DOC DC  
WHERE  RT.DOC_ID = dc_id 
AND RT.DOC_ID = DC.ID
AND RT.DEL_TYPE = 'N'
AND RT.PRSS IN (14);
return(Result);
end FN_NOTECNT;

/* 제출완료 카운트  */
CREATE OR REPLACE FUNCTION FN_SNDCNT ( DC_ID IN VARCHAR)
  RETURN VARCHAR2  
IS
Result VARCHAR(20);
begin
SELECT COUNT(*)  INTO Result
FROM MOUMI_TOT_REPORT RT, MOUMI_TOT_DOC DC  
WHERE  RT.DOC_ID = dc_id 
AND RT.DOC_ID = DC.ID
AND RT.DEL_TYPE = 'N'
AND RT.PRSS IN (6);
return(Result);
end FN_SNDCNT;


/* SEQUENCE 생성 */
CREATE SEQUENCE MOUMI.SQ_MOUMI
INCREMENT BY 1 
START WITH 1 
MINVALUE 0 
NOCYCLE 
ORDER


