Setting Session Globals

From ClassDBI

If you want to change a session global, for just a specific script, let's say nls_date_format, you can do this in your script like:

 #!/usr/bin/perl
 use Your_CDBI::Class;
 $sql_statement = q[alter session set nls_date_format = 'yyyy mon'];
 Your_CDBI::Class->db_Main->do($sql_statement);
 Your_CDBI::Class->create({...,date_field=>'2005 Jan'});

Suppose you want to specify an alternative date/time format for your all your Class::DBI classes. Inside your CDBI base class,

 __PACKAGE__->connection($dsn,$username,$password,{AutoCommit=>1});
 __PACKAGE__->db_Main->do(
     q[alter session set nls_date_format = 'yyyy/mm/dd hh24:mi:ss']
 );

Note that this will initiate a connection as soon as any of your CDBI packages are "use"d.

Also, note that if you run in a persistent environment like mod_perl where your database connection may be lost and reconnected, things that you set in this way will not be set when it reconnects. To fix that, you would need to override db_Main and run the SQL query whenever a new connection is made.