Oracle Tutorial: Cursors with Parameters

Key points: Similar to the Java method, parameters can be passed, the cursor is declared to define parameters after the cursor name, parameters are used in the sql statement, and parameters are passed when the cursor is opened.

 --带参数的游标

 declare

   cursor cur_pricetable(v_ownertype number) is select  from t_pricetable where ownertypeid=v_ownertype;--声明游标

   v_pricetable t_pricetable%rowtype;

 begin

   open cur_pricetable(1);--打开游标

   loop

     fetch cur_pricetable into v_pricetable;--提取游标

     exit when cur_pricetable%notfound;--退出循环游标

     dbms_output.put_line('价格:'||v_pricetable.price||

     ' 吨位:'||v_pricetable.minnum||'-'||v_pricetable.maxnum);

   end loop;

   close cur_pricetable;--关闭游标

 end;     

insert image description here

Guess you like

Origin blog.csdn.net/a772304419/article/details/132479485