gpt4 book ai didi

sql - DBI:bind_param 将字符串转换为 ntext -> nvarchar(max) 和 ntext 不兼容

转载 作者:行者123 更新时间:2023-12-03 23:11:26 25 4
gpt4 key购买 nike

我有一个关于 perl DBI 的 bind_param 的问题。以下 SQL 有效:

my $sth = $dbh->prepare("SELECT id FROM table WHERE id = 'string'");
$sth->execute();

虽然以下没有:
my $sth = $dbh->prepare("SELECT id FROM table WHERE id = ?");
$sth->execute('string');

最后一个查询导致的错误是 [ODBC SQL Server Driver][SQL Server]The data types nvarchar(max) and ntext are incompatible in the equal to operator. (SQL-42000) .

好像是 bind_param ,由 execute 调用, 将“字符串”转换为 ntext。我该如何解决这个问题?

最佳答案

考虑在 SQL 调用之前绑定(bind)值类型:

use DBI qw(:sql_types);

my $sth = $dbh->prepare( "SELECT id FROM table WHERE id = ?" );

my $key = 'string';
my $sth->bind_param( 1, $key, SQL_VARCHAR );

$sth->execute();

关于sql - DBI:bind_param 将字符串转换为 ntext -> nvarchar(max) 和 ntext 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13090907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com