我试图将表名传递给一个获取该表的所有字段名的子程序,将它们存储到一个数组中,然后将该数组与另一个 sql 查询的 fetchrow 结合使用以显示这些字段中的数据。这是我现在拥有的代码:
以表名作为参数的子调用示例:
shamoo("reqhead_rec");
shamoo("approv_rec");
shamoo("denial_rec");
洗发水子:
sub shamoo
{
    my $table = shift;
    print uc($table)."\n=====================================\n";
    #takes arg (table name) and stores all the field names into an array
    $STMT = <<EOF;
    select first 1 * from $table
    EOF
    my $sth = $db1->prepare($STMT);$sth->execute;
    my ($i, @field);
    my $columns = $sth->{NAME_lc};
    while (my $row = $sth->fetch){for $i (0 .. $#$row){$field[$i] = $columns->[$i];}}
    $STMT = <<EOF;
    select * from $table where frm = '$frm' and req_no = $req_no
    EOF
    $sth = $db1->prepare($STMT);$sth->execute;
    $i=0;
    while ($i!=scalar(@field))
    {
    #need code for in here...
    }
}
我正在寻找一种方法来把它变成不需要明确定义的东西......
my ($frm, $req_no, $auth_id, $alt_auth_id, $id_acct, $seq_no, $id, $appr_stat, $add_date, $approve_date, $approve_time, $prim);
while(($frm, $req_no, $auth_id, $alt_auth_id, $id_acct, $seq_no, $id, $appr_stat, $add_date, $approve_date, $approve_time, $prim) = $sth->fetchrow_array())