cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

execute immediate with arbitrary result set

Former Member
5,659

Hello, I recently updated from sybase 9 to 16, big jump! With minimal modifications, everything is working, except one stored procedure that uses execute immediate to return a table with arbitrary columns, row and types. The error I get is: "returned a result set with a different schema than expected SQLCODE=-866, ODBC 3 State="HY000"". So this is the code:

/////////////////////////////////////////////////////////////

ALTER PROCEDURE TouchDB.tc_get_parametre_valeur_table(in arg_id_session char(40), in arg_id_parametre integer, in arg_valeur long varchar)

begin

  declare ls_select long varchar;

  declare ls_executeur long varchar;

  declare ls_dynamique char(1);

  select tc_parametre.executeur, tc_type_parametre.dynamique into ls_executeur, ls_dynamique 
   from dba.tc_parametre INNER JOIN dba.tc_type_parametre on
    tc_parametre.id_tc_type_parametre = tc_type_parametre.id_tc_type_parametre
   where id_tc_parametre = arg_id_parametre;

  if ls_executeur IS NOT NULL AND ls_dynamique IS NOT NULL THEN

    set ls_select = 'select * from ' || ls_executeur || '(' || arg_valeur || ')';

    execute immediate WITH RESULT SET ON ls_select;


  else

    select '';


  end if;


end;

/////////////////////////////////////////////////////////////

Any idea?

Thanks for the help and have a nice day, Louis-Philipe

Accepted Solutions (0)

Answers (1)

Answers (1)

Breck_Carter
Participant

Try turning client statement plan caching off altogether (you are probably interested in the Power And Glory Of SQL rather than Third-Order Performance Effects anyway 🙂

See max_client_statements_cached option

See max_plans_cached

There have been a bazillion performance [cough] improvements between V9 and 16 so it's quite possible one of them is biting you.

VolkerBarth
Contributor
0 Likes

Note, in my understanding client statement caching should only have an effect here if the same client issues an identical SQL statement (i.e. including the same parameters IMHO) several times - whereas the statement with the contained procedure call seems to vary between calls... (at least that's my impression).

Breck_Carter
Participant
0 Likes

yes, indeed... corrections have been made

Former Member
0 Likes

Hello, Thanks Breck for the suggestion. Since the calls tend to change often, I'm not sure it can be used here, but I will do some experimenting to see the new potential.

Breck_Carter
Participant
0 Likes

If the code changes often then caching will not help... but turning it off might make it work.