Created
October 17, 2019 07:03
-
-
Save qlong8807/6887443991a59ab571ee5f9fe5a5ce3b to your computer and use it in GitHub Desktop.
时间+4位随机数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
使用Oracle函数生成主键,时间+4位随机 | |
CREATE OR REPLACE PACKAGE BODY sys_helper_pkg IS | |
FUNCTION get_key_id RETURN INTEGER IS | |
v_key_id INTEGER; | |
v_unix_timestamp INTEGER; | |
v_random_value CHAR(4); | |
BEGIN | |
v_unix_timestamp := (SYSDATE - to_date('2019-10-01', 'yyyy-mm-dd')) * | |
86400; | |
v_random_value := lpad(seq_random_value.nextval, 4, 0); | |
v_key_id := to_number(v_unix_timestamp || v_random_value); | |
RETURN v_key_id; | |
EXCEPTION | |
WHEN OTHERS THEN | |
raise_application_error(-20003, SQLERRM); | |
END get_key_id; | |
END abims_helper_pkg; | |
使用方式: | |
select sys_helper_pkg.get_key_id from dual; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment