小编典典

在 SQL 字符串中转义 & 字符

all

我试图在我的 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);

阅读 210

收藏
2022-09-02

共1个答案

小编典典

代替

node_name = 'Geometric Vectors \& Matrices'

利用

node_name = 'Geometric Vectors ' || chr(38) || ' Matrices'

38 是 & 符号的 ascii 代码,在这种形式下,它将被解释为字符串,仅此而已。我试过了,它奏效了。

另一种方法可能是使用 LIKE 和下划线而不是 ‘&’ 字符:

node_name LIKE 'Geometric Vectors _ Matrices'

你也能找到其他记录的机会,仅在这一个角色中有所不同,这是非常低的。

2022-09-02