0bj*_*3ct 1 sql postgresql type-conversion sqldatatypes
我想使用postgresql to_number(numberString, format_mask).我的numberString可能包含前导零(我不知道这些零的实际长度和numberString总数).我想修剪这些零并将值作为数字.
我在这里阅读了这个函数,目前正在使用以下格式:
select to_number('00005469', '9999999999')
Run Code Online (Sandbox Code Playgroud)
但是如果'9'的长度小于numberString的长度,那么我就无法得到正确的数字.如果不在format_mask中编写一长串'9',我怎样才能完成这项工作?
你不需要to_number()这个.只需将字符串转换为整数:
select '00005469'::integer;
Run Code Online (Sandbox Code Playgroud)
或使用标准SQL:
select cast('00005469' as integer);
Run Code Online (Sandbox Code Playgroud)