Skip to content
Advertisement

Oracle SQL Developer – Getting value from cursor only works with one filter (AND / OR) clause

I am attempting to write a query to retrieve a value from multiple databases and write it to a file. In my function I have a statement which returns results from the cursor:

When I try to modify the filter to add another filter, the results are Null:

Why would the additional filter remove the results?

Here is what the database looks like: Screenshot

Query:

Here is the full function:

Advertisement

Answer

While your date handling (among other things) is problematic, and should be addressed, that isn’t why you are getting null back in this case. Neither is having added a second condition, per se.

If you look at the dynamic statement you are generating in the function as you’ve shown it, with your example schema names of ABC and DEF you’ll get a query string that is 97 characters long*.

When you add the second clause, with a three-character schema name the generated query string is now 130 characters. You can see that here.

So… when you try to assign the string to the cname variable which is defined as:

it will get “ORA-06502: PL/SQL: numeric or value error: character string buffer too small”. But that is happening inside your loop, which has

so the error is suppressed, and nothing is ever appended to the out_str_values variable, so null is returned after the loop. (Suppressing exceptions, particularly with when others, is usually a bug.)

If your list of values includes any values that are longer than 6 characters then those won’t appear in the output string for the shorter query either, but that might not happen or you might not have noticed.

So the immediate fix is to change the size of cname to something large enough for any query you will generate.

* based on the second line of the query embedded in your code appearing to be indented by four spaces; if it is a tab then adjust the numbers…

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement