0

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' 
5
  • Could you show the Perl code which creates $SQL please? Also try printing $SQL to check it's what you think it is. BTW the or die is unnecessary since you have RaiseError on. Commented Mar 20, 2015 at 7:22
  • Is the sql query the content of $SQL? Commented Mar 20, 2015 at 7:24
  • 1
    You have a $ in there. Maybe that confused Perl when creating the query text? Commented Mar 20, 2015 at 7:26
  • yes u got it :) i removed the $ line it works now. Commented Mar 20, 2015 at 8:35
  • how i need to modify my perl connections to accept $ ? Commented Mar 20, 2015 at 8:36

1 Answer 1

0

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{}.

Sign up to request clarification or add additional context in comments.

1 Comment

hi Thilo . thank you very much !!!!!it perfectly works tried my $SQL = q{REGEXP_LIKE (name, 'S.K(Q|S)$')};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.