learn_forever has asked for the wisdom of the Perl Monks concerning the following question:

Hi ! Perl,Oracle,DBI related questions.

I am trying to execute a complext query(select) which retreives about 55000 records. Now when I run this query from SQL*Plus it returns 55000 records, but when I try to run the same query using PERL DBI and get the rows count, it shows only 30000.
Why it is not showing/fetching all the rows which SQL*Plus is able to fetch?

Could anyone help with explaination?
  • Comment on DBI Perl Oracle , returs less number of rows than actual number

Replies are listed 'Best First'.
Re: DBI Perl Oracle , returs less number of rows than actual number
by talexb (Chancellor) on May 31, 2002 at 04:10 UTC
    Are you absolutely positive that you're executing the same SQL statement in both cases?

    What happens when you do a select count (*) instead of select name, year, ... using the prompt and through Perl/DBI .. still the same disagreement?

    --t. alex

    "Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

      Yes sir, I am 101% sure that the SQL is same.

      Now interestingly I tried to run this using TOAD, it returns 55000 records.

      I was suspecting there was some buffer size reated issue so tried to use count(*), add few more columns, drop some columns, nothing changes it rerives 30767 records.

      Is there any known issue with this large number of records? Is there any setting such as CacheInSize or something?

      Alternatively can anyone suggest the debugging technique to check where the record set fails? (Except for prinitng the last retrieved record)
        Alternatively can anyone suggest the debugging technique to check where the record set fails? (Except for prinitng the last retrieved record)

        You have tried DBI->trace(1) already, haven't you?

        --t. alex

        "Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

Re: DBI Perl Oracle , returs less number of rows than actual number
by rdfield (Priest) on May 31, 2002 at 09:45 UTC
    It's probably a quoting issue. Unless you provide the SQL, there's no specific help to be given. One thought though - if you send Oracle an empty string through a DBI placeholder it is evaluated as a NULL. For example: select count(*) from my_table where some_column = ? and the paramater to the execute is the empty string, $sth->execute(''), it is actually executed as select count(*) from my_table where some_column = NULL which will always return 0, since NULL != NULL (or more generally NULL != anything).

    To summarise: it's probably a quoting issue. Try it without placeholders. Have a look in v$sql. Set client_trace_level = admin in your local sqlnet.ora. Turn on DBI tracing. There's loads you can do to isolate the problem

    rdfield

      Thanks !
      I will try these things now. Trace on already there.But does not show why it stopped fetching further records.

      About placeholder, I will try and let you guys know.

      Thanks
Re: DBI Perl Oracle , returs less number of rows than actual number
by lachoy (Parson) on May 31, 2002 at 02:25 UTC

    How are you getting the rowcount? Are you actually fetching the rows and incrementing a counter for each? Or are you looking at the return value for execute()?

    Chris
    M-x auto-bs-mode

      I tried both options
      1. $sth->rows;
      2. fetching all records and the using a counter to itearte through the array.

      Both way I get max 30787 records.

        Only the second way will work. The first is for finding how many rows were affected by an UPDATE/DELETE operation.

        Since DBD::Oracle uses the same libraries as SQL*Plus, that strongly leads me to look at some difference between the Perl invocation and the SQL*Plus invocation: how the queries are constructed, who is creating the query, how are the results fetched.

        Also, what happens when you issue a SELECT COUNT(*) FROM foo WHERE ... in each of the environments?

        Chris
        M-x auto-bs-mode