<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: execute immediate with arbitrary result set in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814001#M4844844</link>
    <description>&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Mar 2015 09:15:03 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2015-03-24T09:15:03Z</dc:date>
    <item>
      <title>execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaq-p/13813994</link>
      <description>&lt;P&gt;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:&lt;/P&gt;
&lt;PRE&gt;/////////////////////////////////////////////////////////////

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;

/////////////////////////////////////////////////////////////
&lt;/PRE&gt;

&lt;P&gt;Any idea?&lt;/P&gt;
&lt;P&gt;Thanks for the help and have a nice day,
Louis-Philipe&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2015 10:41:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaq-p/13813994</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-03-19T10:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813996#M4844839</link>
      <description>&lt;P&gt;The docs tell the following for SQLCODE -866 (SQLE_BAD_RESULT_SET):&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Probable cause&lt;/STRONG&gt;&lt;BR /&gt;
When calling a procedure in the FROM clause of a SELECT statement, the expected schema of the result is taken from the WITH clause. If no WITH clause is given, the expected schema is taken from the system catalog. The result set returned from the call must match the expected schema or it must be possible to convert every column so that it matches. &lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So what does the system catalog reveal for this procedure?&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE&gt;select SPP.*
from sysprocparm SPP key join sysprocedure SP
where proc_name = 'tc_get_parametre_valeur_table'
   and parm_type = 1
order by parm_id


&lt;P&gt;How dou you use this proc inside the FROM clause when its result set will return a different schema dependent on the call?&lt;/P&gt;
&lt;P&gt;A solution might be to dispense with the dynamic result set and to add a RESULT SET clause to the procedure's definition and to simply return no row (but the same schema) when the ELSE branch is executed.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Mar 2015 11:17:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813996#M4844839</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2015-03-19T11:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813997#M4844840</link>
      <description>&lt;P&gt;Hello Volker,
Thanks for the kick reply. I realize that some calls actually works. Weirdly, if the stored procedure called doesn't have any in parameters, the call failed, otherwise it work. Cannot explain that one... &lt;/P&gt;
&lt;P&gt;To answer your question, this is use by a c# platform that create dynamic application on the fly using fun stuff like reflection, generic programming and late binding.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2015 13:21:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813997#M4844840</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-03-19T13:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813995#M4844838</link>
      <description>&lt;P&gt;Try turning &lt;S&gt;client statement&lt;/S&gt; plan caching off altogether (you are probably interested in the Power And Glory Of SQL rather than Third-Order Performance Effects anyway &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;S&gt;See &lt;A href="http://dcx.sybase.com/index.html#sa160/en/dbadmin/dboptions-s-5059985.html"&gt;max_client_statements_cached option&lt;/A&gt;&lt;/S&gt; &lt;/P&gt;
&lt;P&gt;See &lt;A href="http://dcx.sybase.com/index.html#sa160/en/dbadmin/max-plans-cached-dboptions.html"&gt;max_plans_cached&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;There have been a bazillion performance [cough] improvements between V9 and 16 so it's quite possible one of them is biting you.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2015 14:40:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813995#M4844838</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2015-03-19T14:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813998#M4844841</link>
      <description>&lt;P&gt;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).&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2015 05:23:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813998#M4844841</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2015-03-20T05:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813999#M4844842</link>
      <description>&lt;P&gt;Could you show some of the generated SQL statements containing the procedure call?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2015 05:24:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13813999#M4844842</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2015-03-20T05:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814000#M4844843</link>
      <description>&lt;P&gt;yes, indeed... corrections have been made&lt;/P&gt;</description>
      <pubDate>Sun, 22 Mar 2015 08:50:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814000#M4844843</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2015-03-22T08:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814001#M4844844</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2015 09:15:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814001#M4844844</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-03-24T09:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814002#M4844845</link>
      <description>&lt;P&gt;Here's 3 examples:&lt;/P&gt;
&lt;PRE&gt;select * from TouchDB.tc_get_employe_par_depart_data('005');
select * from TouchDB.tc_get_employe_absence_data('005','100001');
select * from TouchDB.tc_get_employe_par_compagnie_data('')
&lt;/PRE&gt;

&lt;P&gt;The last one shouldn't have a parameter since it's not used, but the call fail otherwise. The calls are simple, but the power come from the dynamic nature of the beast.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2015 09:27:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814002#M4844845</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-03-24T09:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814003#M4844846</link>
      <description>&lt;P&gt;If the code changes often then caching will not help... but turning it off might make it work.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2015 09:43:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814003#M4844846</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2015-03-24T09:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814004#M4844847</link>
      <description>&lt;P&gt;Well, I had thought you would need to join the procedure calls with other tables (though that was just my impression, obviously, based on the error code). - If you "just" have to access the result set of a procedure call, I would recommend to call them directly with&lt;/P&gt;
&lt;PRE&gt;call TouchDB.tc_get_employe_par_depart_data('005');
&lt;/PRE&gt;

&lt;P&gt;and the like. AFAIK, that should prevent the -866 error, as the mechanism to describe result sets is somewhat different between direct calls and proc calls within a FROM clause. (I'm by no means aware of those details!).&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2015 11:17:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814004#M4844847</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2015-03-24T11:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: execute immediate with arbitrary result set</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814005#M4844848</link>
      <description>&lt;P&gt;If I read that &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbusage/ptei.html"&gt;enhanced doc topic&lt;/A&gt; correctly, then you could also use SELECT ... FROM proc() when adding an according WITH clause to the FROM clause dynamically - but then you would need both execute immediate in the procedure and in the select statement that uses the proc, and that would not be very useful IMHO...&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2015 11:31:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-arbitrary-result-set/qaa-p/13814005#M4844848</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2015-03-24T11:31:57Z</dc:date>
    </item>
  </channel>
</rss>

