我試圖訪問具有特殊字符名稱中的一個表的錶行,有人可以幫助請:(如何逃避特殊字符在Perl
SELECT
q.user_data.chat_event_text, q.enq_time
FROM
swapp_owner.aq'$'CHAT_EVENT_QUEUE_table q,
CHAT_EVENT_QUEUE_table p
where
q.expiration_reason = 'TIME_EXPIRATION'
and q.msg_id=p.msg_Id
and p.enq_time > (SYSDATE - 50000/(24*60))
order by
q.enq_time desc;
錯誤:
Name "main::CHAT_EVENT_QUEUE_table" used only once: possible typo at ./t21 line 30. Use of uninitialized value $CHAT_EVENT_QUEUE_table in concatenation (.) or string at ./t21 line 30. DBD::Oracle::db prepare failed: ORA-01756: quoted string not properly terminated (DBD ERROR: OCIStmtPrepare) [for Statement "SELECT q.user_data.chat_event_text, q.enq_time FROM swapp_owner.aq' q,CHAT_EVENT_QUEUE_table p where q.expiration_reason = 'TIME_EXPIRATION' and q.msg_id=p.msg_Id and p.enq_time > (SYSDATE - 50000/(24*60)) order by q.enq_time desc; "] at ./t21 line 30. DBD::Oracle::db prepare failed: ORA-01756: quoted string not properly terminated (DBD ERROR: OCIStmtPrepare) [for Statement "SELECT q.user_data.chat_event_text, q.enq_time FROM swapp_owner.aq' q,CHAT_EVENT_QUEUE_table p where q.expiration_reason = 'TIME_EXPIRATION' and q.msg_id=p.msg_Id and p.enq_time > (SYSDATE - 50000/(24*60)) order by q.enq_time desc; "] at ./t21 line 30.
添加完整的腳本:
!/usr/bin/perl -w
BEGIN { $ENV{ORACLE_HOME}='/u01/app/oracle/product/11.1.0/'; } use strict;
use DBI; use utf8;
my $DB='pre14msv'; my $db_user='SWAPP_OWNER'; my $password=`/usr/bin/pmo view password -u $db_user -t $DB`; chomp($password); my $db = DBI->connect("dbi:Oracle:pre14msv", $db_user, $password)
|| die($DBI::errstr . "\n");
$db->{AutoCommit} = 0;
$db->{RaiseError} = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize} = 16;
my $sth = $db->prepare("SELECT q.user_data.chat_event_text, p.enq_time FROM swapp_owner.aq\$\CHAT_EVENT_QUEUE_table q,CHAT_EVENT_QUEUE_table p where q.expiration_reason = 'TIME_EXPIRATION' and q.msg_id=p.msg_Id and p.enq_time > (SYSDATE - 50000/(24*60)) order by q.enq_time desc; "); $sth->execute();
while (my @row = $sth->fetchrow_array()) {
foreach (@row) {
$_ = "\t" if !defined($_);
print "$_\t";
}
print "\n"; }
print "If you see this, execute phase succeeded without a problem.\n";
END {
$db->disconnect if defined($db); }
我已經添加完整的腳本。請看看 – fiddle
嗯,[DBI](http://search.cpan.org/dist/DBI/DBI.pm)'$ sql = $ dbh-> quote($ value);'請參閱鏈接的文檔。 – alexmac