CREATE OR REPLACE FUNCTION LOT_SEQ(P_LOT varchar2 default null)
RETURN VARCHAR2
AS
V_NO NUMBER;
V_NEXT_CHAR CHAR (1);
V_NEXT_LOT CHAR (3);
V_NO1 NUMBER;
V_NO2 NUMBER;
V_LOT char(3);
--V_LOT VARCHAR2 (3) = '000';
BEGIN
if P_lot is null then
select to_char(max(lot_number)) into V_LOT from lot_number;
else
V_LOT := P_LOT;
end if;
SELECT N
INTO V_NO
FROM (SELECT N, CHR (MOD (N, 36) + CASE
WHEN MOD (N, 36) < 10
THEN 48
ELSE 55
END) D
FROM (SELECT ROWNUM - 1 AS N
FROM DUAL
CONNECT BY LEVEL < 37))
WHERE D = SUBSTR (V_LOT, 3, 1);
IF V_NO = 35
THEN
SELECT N
INTO V_NO
FROM (SELECT N, CHR (MOD (N, 36) + CASE
WHEN MOD (N, 36) < 10
THEN 48
ELSE 55
END) D
FROM (SELECT ROWNUM - 1 AS N
FROM DUAL
CONNECT BY LEVEL < 37))
WHERE D = SUBSTR (V_LOT, 2, 1);
IF V_NO = 35
THEN
SELECT N
INTO V_NO
FROM (SELECT N, CHR (MOD (N, 36) + CASE
WHEN MOD (N, 36) < 10
THEN 48
ELSE 55
END) D
FROM (SELECT ROWNUM - 1 AS N
FROM DUAL
CONNECT BY LEVEL < 37))
WHERE D = SUBSTR (V_LOT, 1, 1);
SELECT D
INTO V_NEXT_CHAR
FROM (SELECT N, CHR (MOD (N, 36) + CASE
WHEN MOD (N, 36) < 10
THEN 48
ELSE 55
END) D
FROM (SELECT ROWNUM - 1 AS N
FROM DUAL
CONNECT BY LEVEL < 37))
WHERE N = V_NO + 1;
IF V_NEXT_CHAR IN ('I', 'L', 'O', 'Q', 'T')
THEN
V_NEXT_CHAR := CHR (ASCII (V_NEXT_CHAR) + 1);
END IF;
V_NEXT_LOT := V_NEXT_CHAR || '00';
ELSE
SELECT D
INTO V_NEXT_CHAR
FROM (SELECT N, CHR (MOD (N, 36) + CASE
WHEN MOD (N, 36) < 10
THEN 48
ELSE 55
END) D
FROM (SELECT ROWNUM - 1 AS N
FROM DUAL
CONNECT BY LEVEL < 37))
WHERE N = V_NO + 1;
IF V_NEXT_CHAR IN ('I', 'L', 'O', 'Q', 'T')
THEN
V_NEXT_CHAR := CHR (ASCII (V_NEXT_CHAR) + 1);
END IF;
V_NEXT_LOT := SUBSTR (V_LOT, 1, 1) || V_NEXT_CHAR || '0';
END IF;
ELSE
SELECT D
INTO V_NEXT_CHAR
FROM (SELECT N, CHR (MOD (N, 36) + CASE
WHEN MOD (N, 36) < 10
THEN 48
ELSE 55
END) D
FROM (SELECT ROWNUM - 1 AS N
FROM DUAL
CONNECT BY LEVEL < 37))
WHERE N = V_NO + 1;
IF V_NEXT_CHAR IN ('I', 'L', 'O', 'Q', 'T')
THEN
V_NEXT_CHAR := CHR (ASCII (V_NEXT_CHAR) + 1);
END IF;
V_NEXT_LOT := SUBSTR (V_LOT, 1, 2) || V_NEXT_CHAR;
END IF;
IF V_NEXT_LOT IN
('JAP', 'JEW', 'KKK', 'ASS', 'FUK', 'FUC', 'FAG', 'SEX', 'GAY', 'SOB', 'FU2', 'WTF')
THEN
V_NEXT_LOT := LOT_SEQ;
END IF;
RETURN V_NEXT_LOT;
END;
No comments:
Post a Comment