OTL проблема с oracle с предложением и функцией в нем в C ++ - PullRequest
0 голосов
/ 28 января 2020

Я использую Oracle 18 C (

SQL*Plus: Release 18.0.0.0.0 - Production on Tue Jan 28 02:44:17 2020
Version 18.8.0.0.0

). Я обнаружил эту странную проблему, когда пытался использовать OTL в C ++. У меня есть запрос, который использует предложение "with" из oracle как показано ниже:

with 
FUNCTION
SELECT QUERY with one bind variable

Когда я выполняю этот запрос "with cluase" в pl sql developer, он выполняется гладко. Но когда я помещаю тот же запрос в otl_stream и с переменной bind: он выдает ошибку:

ORA-00600: internal error code, arguments: [15216], [], [], [], [], [], [], [], [], [], [], []

В целях демонстрации я создал временную таблицу и написал запрос:

create table test_with_func
(
int_col NUMBER(9),
varchar_col varchar2(30)
);
insert into test_with_func (INT_COL, VARCHAR_COL)
values (1, 'One');
insert into test_with_func (INT_COL, VARCHAR_COL)
values (2, 'Two');
commit;
with 
function getvalue(in_varchar in varchar2) return integer is out_int NUMBER;
begin
  select int_col
    into out_int
    from test_with_func
   where varchar_col = in_varchar;
  return out_int;
end;
select varchar_col from test_with_func where int_col = getvalue('Two')

Когда я помещаю его в код на c ++, я получаю странную ошибку, упомянутую выше. Ниже приведен мой код C ++.

#include<iostream>
#if defined(solaris32)
#define OTL_ORA9I
#else
#define OTL_ORA12C
#define OTL_UBIGINT unsigned long long
#endif //#if defined(solaris32)
#define OTL_STL // Enable STL compatibily mode
// Now we include OTL
#include <otlv4.h>

otl_connect db; // connect object
using namespace std;

int main(int argc,char **argv)
{
 try{
  db.rlogon("user/password@dbalias"); // connect to Oracle
 }

 catch(otl_exception& p){ // intercept OTL exceptions
  cerr<<p.msg<<endl; // print out error message
  cerr<<p.stm_text<<endl; // print out SQL that caused the error
  cerr<<p.var_info<<endl; // print out the variable that caused the error
 }

 cout<<"Connected to DB"<<endl;
   int mindom=1;
   int maxdom=9999999;
   int minrhash=1;
   int maxrhash=9999999;                                           
 string getDateQuery = " with function getvalue(in_varchar in varchar2) return integer is out_int NUMBER;     \
                         begin                                                                                \
                           select int_col                                                                     \
                             into out_int                                                                     \
                             from test_with_func                                                              \
                            where varchar_col = in_varchar;                                                   \
                           return out_int;                                                                    \
                         end;                                                                                 \
                         select varchar_col                                                                   \
                         from test_with_func                                                                  \
                         where int_col = getvalue(:inputvarchar<char[30]>)";
 string Value;
 otl_stream *getDateStream;
try{
     string var="Two";
     getDateStream=new otl_stream(1, getDateQuery.c_str(), db);
     *getDateStream << var;

     while(!getDateStream->eof())
     {

      *(getDateStream) >> Value;

     }

   }
   catch(otl_exception &p)
   {
       cerr<<p.msg<<endl; // print out error message
       cerr<<p.stm_text<<endl; // print out SQL that caused the error
       cerr<<p.var_info<<endl; // print out the variable that caused the error
   }

  cout<<"Value is "<<Value<<endl;
  db.logoff(); // disconnect from Oracle

return 0;
}

Ниже приведен вывод

]$ ./a.out
Connected to DB
ORA-00600: internal error code, arguments: [15216], [], [], [], [], [], [], [], [], [], [], []

 with function getvalue(in_varchar in varchar2) return integer is out_int NUMBER;                              begin                                                                                                           select int_col                                                                                                  into out_int                                                                                                  from test_with_func                                                                                          where varchar_col = in_varchar;                                                                              return out_int;                                                                                             end;                                                                                                          select varchar_col                                                                                            from test_with_func                                                                                           where int_col = getvalue(:inputvarchar          )

Value is

Это связано с каким-то макросом препроцессора, который я пропустил? Может ли кто-нибудь помочь, пожалуйста, здесь.

1 Ответ

0 голосов
/ 29 января 2020

После изменения запроса с

with 
function getvalue(in_varchar in varchar2) return integer is out_int NUMBER;
begin
  select int_col
    into out_int
    from test_with_func
   where varchar_col = in_varchar;
  return out_int;
end;
select varchar_col from test_with_func where int_col = getvalue('Two')

на

with 
function getvalue(in_varchar in varchar2) return integer is out_int NUMBER;
begin
  select int_col
    into out_int
    from test_with_func
   where varchar_col = in_varchar;
  return out_int;
end;
output as(
select varchar_col from test_with_func where int_col = getvalue('Two')
)
select * from output

Проблема решена в C ++ с использованием OTL. Изменение здесь перемещает последний запрос предложения with в подзапрос и добавляет и новый окончательный запрос выбора. Но учтите, что оба запроса работают через разработчика pl sql. Не уверен, почему первый запрос не работает через OTL в C ++.

...