代码之家  ›  专栏  ›  技术社区  ›  chuck taylor

sql server对exists检查查询的精度无效

  •  0
  • chuck taylor  · 技术社区  · 16 年前

    use DBI;
    $idx = '12345';
    $query = 'if exists (select * from tbl where idx = ?) select top 10 * from tbl';
    my $h = $dbh->prepare($query) or die "Couldn't prepare query: " . $dbh->errstr;
    $h->execute($idx) or die "Couldn't execute statement: " . $h->errstr;
    

    但是请注意,如果我尝试使用此方法

    use DBI;
    $query = 'if exists (select * from tbl where idx = \'12345\') select top 10 * from tbl';
    my $h = $dbh->prepare($query) or die "Couldn't prepare query: " . $dbh->errstr;
    $h->execute() or die "Couldn't execute statement: " . $h->errstr;
    

    那就行了。我真的很困惑怎么了?在查询中,可能导致无效的精度错误。

    谢谢任何人能提供的帮助。

    2 回复  |  直到 16 年前
        1
  •  3
  •   DVK    16 年前

    基于 this article ,请尝试以下操作:

    您需要从DBI导入SQL类型常量 并指定SQL\u LONGVARCHAR作为要添加到memo字段的数据类型。

    为此,您需要:

    $胸径->bind_param(1,$idx,SQL_LONGVARCHAR);

        2
  •  1
  •   bohica    16 年前