我在脚本中使用循环将行插入到数据库中,但是当客户名称包含某些字符时,它将中断。
数据
'1' 'Some+Customer Limited' '[email protected]'
期待中
$a = '1'
$b = 'Some+Customer Limited'
$c = '[email protected]'
INSERT INTO t1 (c1, c2, c3, c4, c5, c6) VALUES ($a, 1, $c, $c, 0, 0);
错误
INSERT INTO t1 (c1, c2, c3, c4, c5, c6) VALUES ('1', 1, 'Some+Customer, Limited' '[email protected]', 0, 0)
*
ERROR at line 1:
ORA-00917: missing comma
如上所示,脚本中没有缺少逗号,即VALUES ($a, 1, $c, $c, 0, 0);
。是因为客户名称中的空格还是客户名称中的空格+
?
我认为问题是read
空格分隔(实际上是$ IFS中包含的任何字符),而不关心引号。
所以代替:
$a = '1'
$b = 'Some+Customer Limited'
$c = '[email protected]'
你有 :
$a = "'1'"
$b = "'Some+Customer"
$c = "Limited' '[email protected]'"
据我所知,没有办法read
在正则表达式上使用“引号引起注意”或拆分,您必须选择一个特殊字符来分隔CSV字段
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句