to_date 中有一个 food_2
参数:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/TO_DATE.html#GUID-D226FA7C-F7AD-41A0-BB1D-BD8EF9440118
所以你可以写 if food_selected_1 == food_1:
same_1 = True
img = pygame.transform.scale(check,(30,30))
screen.blit(img,(285,10))
else:
same_1 = False
if food_selected_2 == food_2:
same_2 = True
img = pygame.transform.scale(check,70))
else:
same_2 = False
if same_1 and same_2:
click_1 = 0
click_2 = 0
或 default... on conversion error
。
还有TO_DATE('01/20/2021' default '01-01-2020' on conversion error,'DD-MM-YYYY')
函数:https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/VALIDATE_CONVERSION.html#GUID-DC485EEB-CB6D-42EF-97AA-4487884CB2CD
,
一种选择是使用 regexp_like
检查日期格式。您发布的示例表明它是 'dd-mm-yyyy'
,这意味着 [2 位数字 - 2 位数字 - 4 位数字]。当然,[43-85-0123]
“匹配”这样的格式但不代表有效日期。无论如何,看看它是否有帮助。在我的示例中,我用今天的日期替换了无效的日期值。阅读代码中的注释。
SQL> with test (col) as
2 -- sample data; the 2nd row is invalid
3 (select 'date-05-03-2020-Tran-100002345-W.44321-CR-9999eu843' from dual union all
4 select 'date-05-032-2020-Tran-100002345-W.44321-CR-9999eu843' from dual
5 ),6 exdate as
7 -- extract "date" substrings (values between 1st and 4th "-" character)
8 (select col,9 substr(col,instr(col,'-') + 1,10 instr(col,'-',1,4) - instr(col,'-') - 1
11 ) datum
12 from test
13 )
14 select col,15 case when regexp_like(datum,'[0-9]{2}-[0-9]{2}-[0-9]{4}') then
16 to_date(datum,'dd-mm-yyyy')
17 else trunc(sysdate)
18 end as result
19 from exdate
20 /
COL RESULT
---------------------------------------------------- ----------
date-05-03-2020-Tran-100002345-W.44321-CR-9999eu843 05-03-2020
date-05-032-2020-Tran-100002345-W.44321-CR-9999eu843 01-08-2021
SQL>
本文链接:https://www.f2er.com/3103.html