petek, 7. december 2018

How to check equality of two SQL select result sets in Oracle


Often you need to know if the new SQL select statement is equivalent to old one. Let’s say You rewrite select and it’s much faster, but is it equivalent to old one? You need to compare result sets of old and new select statements. You can compare result sets with different combinations of bind variables. If you don’t have any bind variables, create them by replacing constant values. If results sets are equal in all test scenarios you are good to go. Probability that new SQL select statement is equivalent to old one is greater, if you test selects with more different combinations of bind variables and if result sets are bigger.

Select for comparing old select with new select is:

WITH old_select as (select …)
,new_select as (select …)
select count(*), ‘diffs’ description from
 (
         (
                select * from old_select
                        minus
                 select * from new_select
             )
             union
             (
                    select * from new_select
                        minus
                    select * from old_select
                )
  )
  union all
  select count(*), 'new_select rows' description from new_select   
  union all
  select count(*), 'old_select rows' description from old_select   
 ;

Following result set means that result sets are equal and that there are 130 rows in each result set.

0      ‘diffs’
130    'new_select rows'
130    'old_select rows'




sobota, 19. december 2015

WebLogic server and java.lang.ClassCastException

I got this exception:
java.lang.ClassCastException: weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB cannot be cast to oracle.sql.BLOB.
It's because WLS properly wraps all vendor-specific types when using a connection pool. Oracle BLOB and CLOB are obviously Oracle specific types. Programmatic solution is usage of getVendorConnection() method.
Other solution is disabling type wrapping on WLS for specific data source.
  • Open WLS Administration Console and select right data source:

  •  Click on tab Connection Pool and expand Advanced settings at the bottom of the page:

  • Uncheck CheckBox Wrap Data Types (again at the bottom of the page) and save changes:


 We needed to restart WLS to activate change. Exception is gone!