在sql语句中调用函数,执行时提示ORA-01722: 无效数字
测试用例和测试结果为 :
1.select func_getprivtypeid(1) from dual;
执行sql语句A报错,提示ORA-01722: 无效数字
2.select func_getprivtypeid(9883) from dual;
执行sql语句A成功,可以通过函数返回结果替换到sql语句A中后,继续执行并反馈sql执行结果
就是这个测试用例1中报【ORA-01722: 无效数字】的错误搞不懂,请大家帮忙分析一下,先谢过了
源程序如下:
待执行的sql语句A(其中调用了函数func_getprivtypeid):select a.id,a.fullname,a.typeid from tablea a,tableb b where a.typeid=b.typeid and a.typeid in (func_getprivtypeid(b.typeid)); create or replace function func_getprivtypeid(p_typeid number) return varchar2
is
l_typeno number;
l_return varchar2(200);
begin
select typeno into l_typeno from tableb where typeid=p_typeid;
if l_typeid=1 then
if p_typeid in (1) then
l_return:='(1230,1231,1234,1234,1235,1236,3762,9883,9903,9843)';
elsif p_typeid not in (1) then
l_return:='(1230,1231,1234,1234,1235,1236,3762)';
end if;
elsif l_typeid=60 then
l_return:=p_typeid;
end if;
return l_return;
end func_getprivtypeid;
测试用例和测试结果为 :
1.select func_getprivtypeid(1) from dual;
执行sql语句A报错,提示ORA-01722: 无效数字
2.select func_getprivtypeid(9883) from dual;
执行sql语句A成功,可以通过函数返回结果替换到sql语句A中后,继续执行并反馈sql执行结果
就是这个测试用例1中报【ORA-01722: 无效数字】的错误搞不懂,请大家帮忙分析一下,先谢过了
源程序如下:
待执行的sql语句A(其中调用了函数func_getprivtypeid):select a.id,a.fullname,a.typeid from tablea a,tableb b where a.typeid=b.typeid and a.typeid in (func_getprivtypeid(b.typeid)); create or replace function func_getprivtypeid(p_typeid number) return varchar2
is
l_typeno number;
l_return varchar2(200);
begin
select typeno into l_typeno from tableb where typeid=p_typeid;
if l_typeid=1 then
if p_typeid in (1) then
l_return:='(1230,1231,1234,1234,1235,1236,3762,9883,9903,9843)';
elsif p_typeid not in (1) then
l_return:='(1230,1231,1234,1234,1235,1236,3762)';
end if;
elsif l_typeid=60 then
l_return:=p_typeid;
end if;
return l_return;
end func_getprivtypeid;
上面的代码是你的原句吗
if l_typeid=1 then
可是l_typeid并没有定义
是l_typeno吧?
请继续分析一下,谢谢了,呵呵
修改后的程序如下:
待执行的sql语句A(其中调用了函数func_getprivtypeid):select a.id,a.fullname,a.typeid from tablea a,tableb b where a.typeid=b.typeid and a.typeid in (func_getprivtypeid(b.typeid)); create or replace function func_getprivtypeid(p_typeid number) return varchar2
is
l_typeno number;
l_return varchar2(200);
begin
select typeno into l_typeno from tableb where typeid=p_typeid;
if l_typeno=1 then
if p_typeid in (1) then
l_return:='(1230,1231,1234,1234,1235,1236,3762,9883,9903,9843)';
elsif p_typeid not in (1) then
l_return:='(1230,1231,1234,1234,1235,1236,3762)';
end if;
elsif l_typeno=60 then
l_return:=p_typeid;
end if;
return l_return;
end func_getprivtypeid;