This is my problem: we have a stored procedure called HEAVY_SP
and depending on how it is executed, execution time is greatly increased:
(1)
Try getting nls parameters from your diferent cases(ide's or java programs) they must be diferent
select * from NLS_SESSION_PARAMETERS
Then inside of your store procedure set the variables to make them equals from the fastest case.
execute immediate 'alter session set NLS_SORT=''SPANISH''';
Once you SP have all nls parameters . It will run fast.
I just recently found a similar case in Alter session slows down the query through Hibernate . but in their case they change de parameters and then became slow.
I investigated and found that The parameters NLS_COMP y NLS_SORT may affect how oracle make uses of execute plan for string ( when it is comparing or ordering)
When NLS_COMP is defined as LINGUISTIC it will use the language define in NLS_SORT.
for example, if NLS_COMP = LINGUISTIC and NLS_SORT=BINARI_AI your querys is
select * from table where string_column like 'HI%'
internally it will do
select * from table where
NLSSORT(string_column,'BINARI_AI') >= HEXTORAW('324242432')
NLSSORT(string_column,'BINARI_AI') >= HEXTORAW('675757576')
so if you dont have a index for NLSSORT(column,'BINARI_AI') it will be very slow.
knowing that NLS_SORT=BINARY_AI will make accent-insensitive and case-insensitive your ordering and comparisons.