stephenjacob
stephenjacob

Reputation: 171

Oracle DBD Error from Perl script

I am trying to run perl script but i get an oracle error.

DBD::Oracle::db prepare failed: ORA-01756: quoted string not properly terminated (DBD ERROR: OCIStmtPrepare) 

But this SQL QUERY perfectly works fine in TOAD

MY perl connection details:

my $dbh = DBI->connect($dsn, $dbuser, $dbpass, { RaiseError => 1, AutoCommit => 0 });
    my $sth=$dbh->prepare($SQL);
    $sth->execute or die "EXEC ERROR $sth->errstr";

sql query:

SELECT name FROM employee WHERE
            event IN ('IPO', 'RIGHTS')
        AND (NOT market_code = 'ID' OR NOT event = 'RIGHTS')
        AND NOT market_code = 'IN'
        AND NOT market_code = 'NZ'
        AND name NOT LIKE '%stat%'
          AND NOT REGEXP_LIKE (name, 'S.K(Q|S)$')
          AND name NOT LIKE '.%'
          AND name NOT LIKE '%ol.SI'
          AND name NOT LIKE '%bi.SI' 

Upvotes: 0

Views: 801

Answers (1)

Thilo
Thilo

Reputation: 262534

Perl will interpolate double-quoted string literals, like

 my $SQL = "REGEXP_LIKE (name, 'S.K(Q|S)$')";

In here, your "variable" $' will be replaced with its value.

If you don't want that, use a non-interpolating version:

 my $SQL = q{REGEXP_LIKE (name, 'S.K(Q|S)$')};

Single-quoted strings would also do, but since you have single quotes inside, the q{} is convenient. You can choose any terminator you want (such as q[]) and you can make it interpolate, too, with qq{}.

Upvotes: 0

Related Questions