我正在尝试按名称查询sql数据库中的某一行,但它有一个“与”号。我试图设置一个转义字符,然后转义与号,但由于某种原因,这不起作用,我不确定我的问题到底是什么。
Set escape '\'
select * from V1144engine.T_nodes where node_id in(
select node2_id from V1144engine.T_edges where node1_id in(
select node2_id from V1144engine.T_edges where node1_id in(
select node2_id from V1144engine.T_edges where node1_id =
(select node_id from V1144engine.T_nodes where node_name = 'Geometric Vectors \& Matrices')))
and edge_type_id = 1)
and node_type_id = 1
and node_id in (
select node2_id from V1144engine.T_edges where node1_id =
(select node_id from V1144engine.T_nodes where node_name = 'Algebra II')
and edge_type_id = 2);
虽然这与this question有类似的解决方案,但问题提出的方式非常不同。它们可能最终会有相同的解决方案,但这并不意味着问题是相同的。
发布于 2012-10-19 02:42:38
而不是
node_name = 'Geometric Vectors \& Matrices'
使用
node_name = 'Geometric Vectors ' || chr(38) || ' Matrices'
38是“与”符号的ascii代码,在这种形式下,它将被解释为字符串,而不是其他。我试过了,它起作用了。
另一种方法是使用LIKE和下划线代替'&‘字符:
node_name LIKE 'Geometric Vectors _ Matrices'
你找到其他记录的机会也很低,只有一个字符有所不同。
发布于 2012-10-19 02:28:07
Escape is set to \
by default,所以您不需要设置它;但是如果您设置了它,请不要用引号括起来。
“&”是SQL*Plus的substitution variable标记;但是您可以使用change it,或者在本例中更有用的是完全关闭它,方法是:
set define off
然后,您根本不需要费心转义该值。
发布于 2012-10-19 02:27:19
您可以使用
set define off
使用此选项将不会提示输入
https://stackoverflow.com/questions/12961215
复制相似问题