小编Gee*_*Gee的帖子

Oracle PL/SQL,我想检索价格最接近4.23的产品的详细信息

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)

我想检索 …

sql oracle plsql

0
推荐指数
1
解决办法
110
查看次数

标签 统计

oracle ×1

plsql ×1

sql ×1