我需要将数据插入到具有特殊字符(例如<>-.....)的表列之一中。 所以我给了\,它用作每个文字的转义字符
这是我要插入的“简介”列的数据。 数据来自csv文件,其中所有数据都用双引号引起来
"<p><span style=""font-family: \'Calibri Light\': sans-serif\; font-size: xx-large\; color: #2184c2\;""><span style=""font-size: 28pt\;""><span style=""font-size: x-large\;""><span style=""font-size: 18pt\;""><strong>Help us improve by taking our short satisfaction survey. \;</strong></span></span></span></span></p>"
当我尝试插入此数据时,出现以下错误。
AnalysisException: Syntax error in line 1:\n...","","<p><span style="font-family: \\\\\'Calibri Light\\\\\'...\n ^\nEncountered: -\nExpected: CROSS, FROM, FULL, GROUP, HAVING, INNER, JOIN, LEFT, LIMIT, OFFSET, ON, ORDER, RIGHT, STRAIGHT_JOIN, TABLESAMPLE, UNION, USING, WHERE, COMMA\n\nCAUSED BY: Exception: Syntax error\n (110) (SQLExecDirectW)')
日志类型-信息日志
有人可以帮助我将此类数据插入表中吗
答案 0 :(得分:0)
分号和单引号需要使用反斜杠转义:
create table test_str as select '<p><span style=""font-family: \'Calibri Light\', sans-serif\; font-size: xx-large\; color: #2184c2\;""><span style=""font-size: 28pt\;""><span style=""font-size: x-large\;""><span style=""font-size: 18pt\;""><strong>Help us improve by taking our short satisfaction survey \;</strong></span></span></span></span></p>';
select * from test_str;
结果:
<p><span style=""font-family: 'Calibri Light', sans-serif; font-size: xx-large; color: #2184c2;""><span style=""font-size: 28pt;""><span style=""font-size: x-large;""><span style=""font-size: 18pt;""><strong>Help us improve by taking our short satisfaction survey </strong></span></span></span></span></p>