我在一个查询中传递了一个日记帐列表,该查询在日记帐名称中包含特殊字符,如&,-'()。下面是我的查询:
select alt_id, citation.doi, citation.journal, citation.volume,
citation.issue, citation.pubdate, citation.title
from ALT_2018
where citation.journal in ('Mechanics & Astronomy', 'Women's Health', 'Current
Directions in Psychological Science (Sage Publications Inc.)', 'Cement &
Concrete Composites', 'Journal of Heart & Lung Transplantation', 'Infection control
and hospital epidemiology (Online)', 'Journal of Research on Adolescence
(Blackwell Publishing Limited)', 'Ophthalmic & Physiological Optics', 'Brain
Structure & Function', 'New Solutions: A Journal of Environmental &
Occupational Health Policy', 'European Physical Journal B -- Condensed
Matter')我尝试使用反斜杠来转义特殊字符,但它不起作用,我也不能手动转义,因为列表由2000+日志组成。请帮帮我。
附注:我使用的是Studio3T中的SQL查询扩展,因为数据是以MongoDB格式保存的,并且是json格式。
发布于 2019-02-03 08:59:17
您可以在此处了解MySQL字符串文字中的特殊字符:https://dev.mysql.com/doc/refman/8.0/en/string-literals.html
如果需要使用撇号字符,可以使用以下方法之一:
'Women\'s Health'
'Women''s Health'
"Women's Health" -- only if sql_mode is not ANSI or ANSI_QUOTES这些都是可以选择的。我不知道你说的“它不工作”是什么意思,所以我不能建议如何修复它。我不使用Studio3T,所以我猜不出是什么阻止您使用这些解决方案之一。
MySQL字符串文字中的&字符没有什么特别之处。
https://stackoverflow.com/questions/54497373
复制相似问题