时间:2024-02-13 10:22作者:下载吧人气:28
新建一个函数,用来生成身份证号码,需要输入两个日期参数
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;
网友评论