我需要将日期字符串-'2013-01-01'转换为数字--20130101类型。如何有效地在Oracle中完成它?
My Input-
'2013-01-01'
My Output
Output-20130101
答案 0 :(得分:5)
select to_number(replace('2013-01-01', '-')) from dual;
答案 1 :(得分:2)
to_char(your_date,'YYYYMMDD')
这里使用带有日期的to_char的基础知识。
答案 2 :(得分:2)
您可以将字符串转换为日期并使用您想要的格式转换回来:
select to_char(to_date('2013-01-01', 'YYYY-MM-DD'), 'YYYYMMDD');
有关日期时间格式的更多信息:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm
答案 3 :(得分:0)
您还可以“利用”格式掩码:
select to_number('2013-01-01', '9999G99G99', 'nls_numeric_characters=,-')
from dual
答案 4 :(得分:0)
要将日期字符串转换为数字:
始终先将其转换为char然后转换为数字:
SEQUENCE CHECK_TIME DEVICE ORIGIN NAMESPACE SERVICE_CHECK VALUE TAGS
0 2020-06-24T02:00:05.441Z kubeflow-vm vm.azm.ms/map Computer Heartbeat 1 {"vm.azm.ms/processIds":["p-96566f30b8066a6479008755c528d7920511edc8","p-9f6667971df49fed675576b8f936cc45a61d242d","p-cfc973bcf0a32b902410a7b16cd977d6bb264e62","p-39a51e264bf790ec9e4a6902ead00101c1e78c97","p-d63478488b88c35f85a2c11e07642dddec84ef62","p-ce8cf40e9b45c9db18007f181460e21587af3267","p-e2643b874c714b4dd182003298ad59268f7f6b5b","p-0efa4aa396315bfcd87632237460ab0c12124c46","p-642d2b7e86ff01c62bc11f858e074e741d54d37b","p-0a3fbb9d81230bee9daaa2ce8262bb5357debb69","p-f61381ae6a9c8cdad1f241c9c456015658a8f925","p-f3f604a0313bc1778e69c9203a0162d1abfedad2","p-6dec6d0558740906471b6d3ee920cce37faeca70","p-27613669fcf7faaeef5023acc6505973e12d2db5","p-d97d079b692dcb81adb5ed5dc48d29c82ef6f93a","p-44507943475c4fb04f09595617020da7ac2c388c"]}
如果您的列数据类型为DATE,则在下面使用您的列名代替sysdate:
Select TO_NUMBER(TO_CHAR(to_date('2013-01-01', 'YYYY-MM-DD'),'YYYYMMDD')) from dual