欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

函数参数与表名相同导致的问题

程序员文章站 2022-03-15 19:41:38
...
create or replace function F_HB_GET_VERIFY_TIME(projectid in number,positionid in number) return varchar2 is
-- 根据projectid和positionid查询该项目该领导的批示时间和批示内容。
  Result varchar2(32767);
  i number :=0;
begin
   for rs in (
      select p.approve_date,p.instruct from processtable p where p.projectid = projectid and p.position_id = positionid
   ) loop
     Result := Result ||'【'|| to_char(rs.approve_date,'yyyy-MM-dd')||'】:'||rs.instruct;
   end loop;

     --dbms_output.put_line('aa:'||Result);
  return(Result);
end F_HB_GET_VERIFY_TIME;

 

rs 返回的结果不正确,细查后发现,processtable 表字段有一个为projectid,  函数的参数projectid与表中的一个字段相同,所以,当rs执行语句

select p.approve_date,p.instruct from processtable p where p.projectid =projectid and p.position_id = positionid

 其实相当于

select p.approve_date,p.instruct from processtable true and p.position_id = positionid 

 

相关标签: F#