【问题标题】:DBI binding parameters and square bracketsDBI 绑定参数和方括号
【发布时间】:2017-03-26 03:19:21
【问题描述】:

以下代码有问题:

$sql = <<"END_SQL";
SELECT DISTINCT Matching.[CI M], Matching2_1.[LAC M], Matching2_1.[CI M], Matching.[Band M], Matching2_1.[Band M], Matching.Site, Matching2_1.Site, Matching.[BSC/RNC], Matching.[CellName M],  Matching.[BSC/RNC M], Matching2_1.[CellName M]
FROM Matching, [N 900 - 900], Matching AS Matching2_1
WHERE Matching.[Band M]= ? AND Matching2_1.[Band M]= ? ;
END_SQL

$sth = $dbh->prepare($sql);
$sth->execute(900, 900);

列名包含空格,数据库是 MS 访问,所以我使用方括号在查询中使用它们

问题在于 Perl 将方括号解释为绑定参数,并且需要 11 个参数。

这是错误:

DBD::ODBC::st 执行失败:[Microsoft][ODBC Microsoft Access Driver] 参数太少。预计 11. (SQL-07002) 在 NEIGHBORS MAPPING.pl 第 89 行。

【问题讨论】:

标签: perl ms-access dbi brackets square


【解决方案1】:

Access 数据库引擎还可以将反引号识别为表/字段分隔符,因此如果方括号给您带来麻烦,请尝试

SELECT DISTINCT Matching.`CI M`, ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 2023-03-20
    • 2012-01-17
    • 2017-02-27
    相关资源
    最近更新 更多