Oracle B12255-01 Manuale Utente

Pagina di 224
mod_perl
7-18
Oracle HTTP Server Administrator’s Guide
This release of DBD::Oracle supports SQL NCHAR datatypes and provides driver
extension functions to specify the character form for data binding. The following
script shows an example to access SQL NCHAR data:
Example 7–3
Sample Script to Access SQLNCHAR Data
# declare to use the constants for character forms
use DBD::Oracle qw(:ora_forms);
# connect to the database and get the database handle
$dbh = DBI->connect( ... );
# prepare the statement and get the statement handle
$sth = $dbh->prepare( 'SELECT * FROM TABLE_N WHERE NCOL1 = :nchar1' );
# bind the parameter of a NCHAR type
$sth->bind_param( ':nchar1', $param_1 );
# set the character form to NCHAR
$sth->func( { ':nchar1' => ORA_NCHAR } , 'set_form' );
$sth->execute;
As shown in
, the
 function is provided as a private function
that you can invoke with the standard DBI func() method. It takes an anonymous
hash that specifies which placeholder should be associated with which character
form. The valid values of character form are either ORA_IMPLICIT or ORA_NCHAR.
Setting the character form to ORA_IMPLICIT causes the application's bound data to
be converted to the database character set, and ORA_NCHAR to the national character
set. The default form is ORA_IMPLICIT.
Another function is provided to specify the default character set form as follows:
# specify the default form to be NCHAR
$dbh->func( ORA_NCHAR, 'set_default_form' );
After this call is made, the form of all parameters is ORA_NCHAR, unless otherwise
specified with set_form calls. Note that unlike the set_form function, this is a
function on the database handle, so every statement from the database handle with
its default form specified has the form of your choice by default.