0°

Oracle使用SQL语句判断身份证号码的性别,身份证哪几位是性别

Oracle数据库,当表示日期的字段类型为DATE时,在进行一般时间查询时,可将时间转换为字符串,再进行判断。

To_char(date,’YYYY-MM-DD’) = ‘2019-09-26’
To_char(UPDATE_DATE,'YYYY-MM-DD') = to_char(sysdate,'yyyy-mm-dd')

Oracle内根据身份证号码判断性别:

decode(mod (to_number( substr(t.身份证号 ,17, 1)),2 ),0, '女','男' ) as 提取性别
select 
decode(mod (to_number( substr(t.idcard ,17, 1)),2 ),0, '女','男' ) as sex
 from table_test t;

Oracle根据身份证判断性别:

select decode(mod (to_number(substr('110228197802199547' ,17, 1)),2 ),0, '女','男' ) as sex from dual ;
 
select decode(mod (to_number(substr('530323197503252610' ,17, 1)),2 ),0, '女','男' ) as sex from dual ;
 
select decode(mod (to_number(substr('110228197802199547' ,17, 1)),2 ),0, '2','1' ) as sex from dual ;
 
select decode(mod (to_number(substr('530323197503252610' ,17, 1)),2 ),0, '2','1' ) as sex from dual ;
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论