Sql 在Oracle中,translate函数做什么
我知道解码功能,但是不知道翻译中的东西是什么意思:Sql 在Oracle中,translate函数做什么,sql,oracle,decode,Sql,Oracle,Decode,我知道解码功能,但是不知道翻译中的东西是什么意思: decode(translate(cookie_id,'0123456789','') = '','t',cookie_id,null) as cookie_id decode((translate(pickup_date,'0123456789','') = '--' and length(pickup_date) = 10),'t',pickup_date,null) as pickup_date, 这很简单。这句话: translat
decode(translate(cookie_id,'0123456789','') = '','t',cookie_id,null) as cookie_id
decode((translate(pickup_date,'0123456789','') = '--' and length(pickup_date) = 10),'t',pickup_date,null) as pickup_date,
这很简单。这句话:
translate(cookie_id, '0123456789', '')
返回NULL
。Oracle将空字符串视为NULL
,甚至明确警告:
您不能使用to_字符串的空字符串来删除所有字符
从返回值中输入from_字符串。Oracle数据库解释
空字符串为null,如果此函数具有null参数,则
它返回null
因此,对于cookie\u id
,第一个示例始终会产生NULL
很可能,作者的意图是:
decode(translate(cookie_id, 'a0123456789', 'a'), '', cookie_id, null) as cookie_id
这将检查cookie\u id是否只包含数字,然后返回id。我个人认为正则表达式更容易理解:
(case when regexp_like(cookie_id, '^[0-9]+$') then cookie_id end)
这不需要做一些古怪的事情来处理空字符串