declare
total number := 0;
phone varchar2(11) := '18892543659';
begin
select count(*) into total from user where account=phone;
dbms_output.put_line(total);
end;
输出内容为:77362
而表中并没有这个电话号码,所以并没有得到正确的结果,而换成以下代码后得到了我们想要的结果。
declare
total number := 0;
phone varchar2(11) := '18892543659';
user_phone varchar2(11);
begin
user_phone := phone;
select count(*) into total from jkfp_sys_user where account=user_phone;
dbms_output.put_line(total);
end;
这次输出的内容为0,这才是正确的结果。
第二段代码与第一段代码的区别是我们重新定义了一个变量,将入参赋值给这个变量。