[英]OTL problem with oracle with clause and function in it in C++
我正在使用 Oracle 18C(
SQL*Plus: Release 18.0.0.0.0 - Production on Tue Jan 28 02:44:17 2020
Version 18.8.0.0.0
) 當我嘗試在 C++ 中使用 OTL 時,我發現了這個奇怪的問題我有一個使用 oracle 的“with”子句的查詢,如下所示:
with
FUNCTION
SELECT QUERY with one bind variable
當我在 plsql developer 中執行這個“with cluase”查詢時,它執行順利。 但是當我在 otl_stream 和綁定變量中放入相同的查詢時:它拋出一個錯誤:
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
這與我錯過的一些預處理器宏有關嗎? 任何人都可以在這里幫忙。
更改查詢后
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 子句的最后一個查詢移動到子查詢中,並添加了新的最終選擇查詢。 但請注意,這兩個查詢都通過 plsql developer 工作。 不知道為什么第一個查詢不能通過 C++ 中的 OTL 工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.