時間:2024-02-13 10:22作者:下載吧人氣:22
新建一個函數,用來生成身份證號碼,需要輸入兩個日期參數
create or replace function gen_id(
a date,
b date
)
returns text as $$
select lpad((random()*99)::int::text, 2, ‘0’) ||
lpad((random()*99)::int::text, 2, ‘0’) ||
lpad((random()*99)::int::text, 2, ‘0’) ||
to_char(a + (random()*(b-a))::int, ‘yyyymmdd’) ||
lpad((random()*99)::int::text, 2, ‘0’) ||
random()::int ||
(case when random()*10 >9 then ‘X’ else (random()*9)::int::text end ) ;
$$ language sql strict;
網友評論