declare
  type rec_merchandise is record
  (
    v_id 商品信息.商品编号%type,
    v_name 商品信息.商品名称%type,
    v_place 商品信息.产地%type,
    v_price 商品信息.单价%type
  );
  
  merchandise_row rec_merchandise;
  
  type c_merchandise(place in varchar2) is ref cursor;
  v_merchandise c_merchandise;
  
begin
  open v_merchandise('北京市') for select 商品编号,商品名称,产地,单价
       from 商品信息 where 产地=place;
  
  loop
    fetch v_merchandise into merchandise_row;
    exit when v_merchandise%notfound;
    dbms_output.put('商品编号:'||merchandise_row.v_id);
    dbms_output.put('/商品名称:'||merchandise_row.v_name);
    dbms_output.put('/产地:'||merchandise_row.v_place);
    dbms_output.put_line('/单价:'||merchandise_row.v_price);
  end loop;
  close v_merchandise;
end;-------
请问各位大虾,以下脚本为什么会报错?
type c_merchandise(place in varchar2) is ref cursor;
  v_merchandise c_merchandise;
  
begin
  open v_merchandise('北京市') for select 商品编号,商品名称,产地,单价
       from 商品信息 where 产地=place;用游标变量不能定义参数和传参数的吗?---
待复,感谢!

解决方案 »

  1.   

    open v_merchandise for 'select 商品编号,商品名称,产地,单价
      from 商品信息 where 产地=:place' using '北京市';
      

  2.   

    --同一楼,使用USING语句将引用到的值传给动态SQL语句'产地=:place' 中的'place'
    open v_merchandise for 'select 商品编号,商品名称,产地,单价  from 商品信息 
    where 产地=:place' using '北京市';或者   --声明显示游标cursor v_merchandise(place varchar2) is select 商品编号,商品名称,产地,单价
      from 商品信息 where 产地=place;            
    begin
        open v_merchandise('北京市'); --打开游标