DBD :: Oracle :: db准备失败:ORA-00936:缺少表达式(DBD错误:错误可能接近char的< *>指示符

时间:2017-10-13 18:05:36

标签: sql oracle perl

我有2个表A和B.我在数组var1中获取表A的每一行的名称值,然后将数组var1的值放在a的WHERE条件中SELECT表查询B并打印表B的SELECT查询结果。

代码:

my $sql2 = 'select name,value from A';

my $sth2 = $dbh1 ->prepare($sql2);
$sth2 ->execute();
while (my @row = $sth2 ->fetchrow_array)
{
    print join(',', @row), "\n\n";
    push(@var1, $row[0]);
}

foreach(@var1 ) {
    print "$_\n";
}

print "\n";

my $sth3 = $dbh ->prepare("select name, value from B where  name in (".join(", ",@var1).")"); -  line 99
$sth3 ->execute(@var1);

while (my @row = $sth3 ->fetchrow_array)    
{
    print join(", ", @row), "\n";
}

但是得到错误:

  

DBD :: Oracle :: db准备失败:ORA-00904:" 5":无效标识符   (DBD错误:错误可能接近< >指示符在char 143的'选择   名称,来自B的值,其中名称在(1,2,3,4,< > 5)')[for Statement" select   名称,来自B的值,其中名称在(1,2,3,4,5)"]中,位于hello.pl第99行。   无法调用方法"执行"在hello.pl行的未定义值上   102。

1 个答案:

答案 0 :(得分:0)

您使用的查询不正确

select name,value from A where in (1,2,3,4,5)

Where和In

之间添加列名
select name,value from A where *column_you_checking* in (1,2,3,4,5)

my $sth3 = $dbh->prepare(select name,value from B where *column_you_checking* in(".join(",",@var1)."));   -  line 99