Execute SQL file in Perl

前端 未结 4 440
一向
一向 2020-12-10 17:53

We have a Perl script which runs a SQL and puts data in the table. Now instead of supplying a single SQL statement, we want to pass bunch of them putting them together in a

4条回答
  •  生来不讨喜
    2020-12-10 18:36

    Here is how I've done it. In my case I dont assume one SQL per line and I assume, my example is a bit better :)

    sub get_sql_from_file {
        open my $fh, '<', shift or die "Can't open SQL File for reading: $!";
        local $/;
        return <$fh>;
    };
    
    my $SQL = get_sql_from_file("SQL/file_which_holds_sql_statements.sql");
    my $sth1 = $dbh1->prepare($SQL);
    $sth1->execute();
    

提交回复
热议问题