時(shí)間:2024-02-13 10:22作者:下載吧人氣:24
新建一個(gè)函數(shù),用來生成身份證號(hào)碼,需要輸入兩個(gè)日期參數(shù)
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;
網(wǎng)友評(píng)論