On Wed, May 25, 2011 at 11:45:13 +0000 , Marco van Kammen wrote:
> Hi List,
>
> I'm struggeling with the following:
>
> There is a blob field in the oracle db which contains xml...
> I want to read this blob and make a single xml file out of it...
> Now when using the code below I get the data out of the blob with parts of
> xml but its all messed up...
> [nasty encoded data snipped]
Are you certain the column isn't encoded somehow, say with a compression
algorithm or something of that sort? What do Oracle's docs say on the
matter?
> #!/usr/bin/perl
> use warnings;
> use strict;
> use DBI;
>
> my $db = DBI->connect("dbi:Oracle:host=????;sid=???", "???", "???",
> {RaiseError => 1}) or die "$DBI::errstr";
>
> open XML, ">./xmlfile"
> or die "Can't create xml file ($!)";
>
> # Set Max BLOB size
> $db->{LongReadLen} = 150000;
>
> # Select statement
> my $SEL = "select xml_message from table where bla = 'bla'";
>
> # Prepare select
> my $sth = $db->prepare($SEL);
>
> # Execute select
> $sth->execute();
> my @row = $sth->fetchrow_array();
>
> print XML "$row[0]\n";
>
> # Disconnect from DB when finished
> $db->disconnect if defined($db);
Your DBI code looks reasonable. I would suggest using the three-argument
form of open with a lexical filehandle, though, like so:
open my $xml, '>', './xmlfile' or die ...
This way is safer and more robust, plus $xml is easier to deal with than
the global XML (try passing XML to a function: it's not immediately
obvious how). I can't see this as related to your issue, but it's good
form nonetheless.
--
Chris Nehren | Coder, Sysadmin, Masochist
Shadowcat Systems Ltd. | http://shadowcat.co.uk/
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/