c++ - 在 C++ 中带有子句和函数的 oracle 的 OTL 问题
问题描述
我正在使用 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
使用 OTL 在 C++ 中解决了问题。此处的更改是将 with 子句的最后一个查询移动到子查询中,并添加了新的最终选择查询。但请注意,这两个查询都通过 plsql developer 工作。不知道为什么第一个查询不能通过 C++ 中的 OTL 工作。
推荐阅读
- php - 所有异常情况下的 Laravel 电子邮件通知
- css - 关闭图标未放置在正确的位置
- php - 谷歌金融货币转换器不工作
- javascript - 将常量值分配给变量
- casting - Coq:使用类型相等来检查定义中的术语
- c++ - GCC 中 __attribute__((unused)) 和 __attribute((unused)) 的区别
- jenkins-job-dsl - Jenkins job DSL - 让 jenkins 签出特定的提交
- ruby - 从 excel 文件中读取特定列并写入另一个 excel 文件
- reactjs - React-Native + Mobx + React Navigation:错误:MobX 注入器:存储“...”不可用!确保它是由某个 Provider 提供的
- python - 使用参数网格的自定义 GridSearch 用于隔离森林