函数参数与表名相同导致的问题
程序员文章站
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
推荐阅读
-
C语言中值得深入知识点----数组做函数参数、数组名a与&a区别、数组名a的"数据类型"
-
JavaScript中setInterval函数应用常见问题之一(第一个参数不加引号与加引号的区别)
-
存储过程传递参数与表中字段属性相同导致错误的问题_MySQL
-
存储过程传递参数与表中字段属性相同导致错误的问题_MySQL
-
C语言中值得深入知识点----数组做函数参数、数组名a与&a区别、数组名a的"数据类型"
-
php的内置函数create_function创建出来的函数 参数列表与函数体引号问题
-
JavaScript中setInterval函数应用常见问题之一(第一个参数不加引号与加引号的区别)
-
函数参数与表名相同导致的问题