最近在cndba社区里面有一篇文章,作者怀疑是达梦变量作用域的bug。
自己分析了下发现主要问题是因为在函数中未指定DETERMINISTIC关键字导致的,原始文章连接如下:(
https://www.cndba.cn/fancyghost123/article/22703)
修改后的如下:
--PACKAGE信息:
create or replace package test_pack is
function set_useId(useId varchar2) return varchar2 deterministic;
function get_useId return varchar2 deterministic;
end test_pack;
/
create or replace package body test_pack is
paramuseId varchar2(50);
-- Param
function set_useId(useId varchar2) return varchar2 is
begin
paramuseId:=useId;
return useId;
end;
function get_useId return varchar2 is
begin
return paramuseId;
end;
end test_pack;
/
create table t1(id int,c1 varchar2(100),c2 varchar2(100) );
create table t2(id int,c1 varchar2(100),c2 varchar2(100) );
insert into t1 values(1,'a','a');
insert into t2 values(1,'a','a');
insert into t1 values(2,'b','b');
insert into t2 values(2,'b','b');
insert into t1 values(3,'c','c');
insert into t2 values(3,'c','c');
commit;
create or replace view test_view as
SELECT t1.c1 from t1 inner join t2 on t1.c1 = t2.c1
where t2.c1 in (test_pack.get_useId())
or t2.c2 in (test_pack.get_useId());
select * from test_view where test_pack.set_useId('a')='a';
--执行查询
select * from test_view where test_pack.set_useId('a')='a';
这样修改后和Oracle一致了。
文章
阅读量
获赞