in reply to Re: How to Fetch records from Oracle DB view
in thread How to Fetch records from Oracle DB view

I tried the code but again got the error - "Not a Hash reference at dbcsv.pl line 58" where line 58 is. Please help.
  • Comment on Re^2: How to Fetch records from Oracle DB view

Replies are listed 'Best First'.
Re^3: How to Fetch records from Oracle DB view
by afoken (Chancellor) on Sep 04, 2009 at 13:49 UTC

    It can't work -- compare your piece of code with the one kennethk posted.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^3: How to Fetch records from Oracle DB view
by kennethk (Abbot) on Sep 04, 2009 at 14:35 UTC
    Another issue I missed - you've used fetchall_arrayref() (see DBI) and then attempted to access the results as a hash. Part of the issue is of course that I can't run your script to test it since I don't have access to your database so I can't debug. I can only guess that your code through the execute is functioning correctly. I do note that you are mixing hash and array access concepts in accessing the results. As per the documentation,

    The fetchall_arrayref method can be used to fetch all the data to be returned from a prepared and executed statement handle. It returns a reference to an array that contains one reference per row.

    So based on what I'm reading, you first need to modify your SQL to only select the column you are looking for (ROW_DATA presumably) and then access the results like an array reference:

    foreach my $record (@$row1) { $report.= "$row1->[0]\n"; }

    Alternatively, you could change the 0 in the above to reflect the appropriate column for what you are trying to do. Please read perlreftut, DBI and a review of Perl variable types might not be a bad idea. As well, please read the error messages and consider what they say.