Oracle 生成 GUID 类型 [转]
CREATE OR REPLACE FUNCTION AILDM_GET_GUID
RETURN CHAR
IS
v_guid CHAR (36);
v_guid_part_one CHAR (8);
v_guid_part_two CHAR (4);
v_guid_part_three CHAR (4);
v_guid_part_four CHAR (4);
v_guid_part_five CHAR (12);
BEGIN
SELECT SYS_GUID ()
INTO v_guid
FROM DUAL;
v_guid_part_one := SUBSTR (v_guid, 0, 8);
v_guid_part_two := SUBSTR (v_guid, 8, 4);
v_guid_part_three := SUBSTR (v_guid, 12, 4);
v_guid_part_four := SUBSTR (v_guid, 16, 4);
v_guid_part_five := SUBSTR (v_guid, 20, 12);
v_guid :=
CONCAT
(CONCAT
(CONCAT
(CONCAT (CONCAT (CONCAT (CONCAT (CONCAT (v_guid_part_one,
'-'),
v_guid_part_two
),
'-'
),
v_guid_part_three
),
'-'
),
v_guid_part_four
),
'-'
),
v_guid_part_five
);
RETURN (v_guid);
END AILDM_GET_GUID;
RETURN CHAR
IS
v_guid CHAR (36);
v_guid_part_one CHAR (8);
v_guid_part_two CHAR (4);
v_guid_part_three CHAR (4);
v_guid_part_four CHAR (4);
v_guid_part_five CHAR (12);
BEGIN
SELECT SYS_GUID ()
INTO v_guid
FROM DUAL;
v_guid_part_one := SUBSTR (v_guid, 0, 8);
v_guid_part_two := SUBSTR (v_guid, 8, 4);
v_guid_part_three := SUBSTR (v_guid, 12, 4);
v_guid_part_four := SUBSTR (v_guid, 16, 4);
v_guid_part_five := SUBSTR (v_guid, 20, 12);
v_guid :=
CONCAT
(CONCAT
(CONCAT
(CONCAT (CONCAT (CONCAT (CONCAT (CONCAT (v_guid_part_one,
'-'),
v_guid_part_two
),
'-'
),
v_guid_part_three
),
'-'
),
v_guid_part_four
),
'-'
),
v_guid_part_five
);
RETURN (v_guid);
END AILDM_GET_GUID;