create or replace procedure nearprice
is
userprice products.price%type := 4.23;
closest products.price%type;
temp products.price%type;
tempid products.pid%type;
cursor procur is
select * from products;
prorec procur%rowtype;
begin
open procur;
fetch procur into prorec;
closest := abs(prorec.price - userprice);
tempid := prorec.pid;
while procur%found then
loop
fetch procur into prorec;
temp := abs(prorec.price - userprice);
if temp < closest then
closest := temp;
tempid = prorec.pid;
end if;
end loop;
close procur;
select *
from products
where pid = tempid;
end;
Run Code Online (Sandbox Code Playgroud)
我想检索 …