John,

Thanks for the second copy, since I forgot to send a copy of my reply to
the list.

I hope all your machines are in the same time zone -- mine aren't.

The appended variant on your snippet produces the following output:
C:\>perl trw.pl user/[EMAIL PROTECTED]
2003/02/24 11:40:06
Perl date is Mon Mar 24 11:40:06 2003

C:\>

Note that the scope of my $mydate is wrong for your application (local to the "else" 
block).

But on the other hand, if you have administrative access to the remote
machines, and their software is reasonably current, you don't need to query
Oracle to get the time - you can use WMI. Dave Roth's web site () has WMI
examples; above that all you need is what class to ask for instances of,
and it's (suprise! suprise!) Win32_OperatingSystem.

Tom Wyant

use strict;
use warnings;
use DBI;
use Time::Local;

my ($usr, $pwd, $dsn) =
      $ARGV[0] =~ m|^(\w*)(?:/(\w+))?(?:[EMAIL PROTECTED]([\w.]+))?|;
my $dbh = DBI->connect("dbi:Oracle:$dsn",$usr,$pwd) or die
"$DBI::errstr\n";

$dbh->do ("alter session set NLS_DATE_FORMAT = 'YYYY/MM/DD HH24:MI:SS'");
##TRW my $sth = $dbh->prepare(qq{select sysdate into :mydate from dual});
my $sth = $dbh->prepare(qq{select sysdate from dual});

if (! ($sth->execute())) {
    print "$DBI::errstr\n";
}else{
    my $row = $sth->fetchrow_array;
    print "$row\n";
    my $mydate = timelocal (reverse split '\D+', $row);
    print "Perl date is ", scalar (localtime $mydate), "\n";
}

$sth->finish;
$dbh->disconnect;
__END__




John Deretich <[EMAIL PROTECTED]>@listserv.ActiveState.com on
02/24/2003 10:17:46 AM

Sent by:    [EMAIL PROTECTED]


To:    "'Fay Jason-W13246'" <[EMAIL PROTECTED]>,
       "Perl-Win32-Admin-Request \(E-mail\)"
       <[EMAIL PROTECTED]>
cc:
Subject:    RE: sql statements


Thanks for the info.

I am actually trying to get
the time on our oracle data base
and compare it to the local time on
each machine. Then if there's
a difference + or - say 10 minutes.
Put it into a report showing
that the machine needs to be reset.

Is there a way to convert the
HH24:MI:SS to total seconds?
I need to compare it to the time
in seconds on each machine.

regards,

John

-----Original Message-----
From: Fay Jason-W13246 [mailto:[EMAIL PROTECTED]
Sent: Friday, February 21, 2003 6:11 PM
To: Perl-Win32-Admin-Request \(E-mail\)
Subject: RE: sql statements


>Hi cliff,
>
>I plugged that statement into my
>code and it's still having a problem.
>Could you take a look at my code to
>see what the problem could be:
>
>$dbh = DBI->connect("dbi:Oracle:",'username','password');
>
>my $sth = $dbh->prepare(qq{select sysdate into :mydate from dual});
>
>if ( $sth ) {
>       $sth->execute;
>        }
>$dbh->disconnect;
>
>regards,
>
>John

When using the DBI / DBH modules, you don't need to bind an Oracle variable
(ie 'into :mydate') as you are in this example.  Change your query from
'select sysdate into :mydate from dual' to 'select sysdate from dual' and
then put the query result from your sth handle into a scalar variable.

Now if you want to change the default format that Oracle uses for date
datatypes, (ie YYYY-MM-DD) you would need to further modify your query.
'select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual'.

Regards,

Jason Fay
Software Engineer - Motorola PCS

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs





This communication is for use by the intended recipient and contains 
information that may be privileged, confidential or copyrighted under
applicable law.  If you are not the intended recipient, you are hereby
formally notified that any use, copying or distribution of this e-mail,
in whole or in part, is strictly prohibited.  Please notify the sender
by return e-mail and delete this e-mail from your system.  Unless
explicitly and conspicuously designated as "E-Contract Intended",
this e-mail does not constitute a contract offer, a contract amendment,
or an acceptance of a contract offer.  This e-mail does not constitute
a consent to the use of sender's contact information for direct marketing
purposes or for transfers of data to third parties.

 Francais Deutsch Italiano  Espanol  Portugues  Japanese  Chinese  Korean

            http://www.DuPont.com/corp/email_disclaimer.html


_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to