我这个SQL为什么实现不了啊,不要管我的语法,这只是原型,
就是想用游标遍历基表,得到ITEM,然后在另外表中根据ITEM查找出PRICE,逻辑很简单,
估计问题出在:
"insert into 我的价格表(item,price)
select item,price from 价格表 where 价格表.item=item_v;"
但我不知道究竟是如何错的?
declare item_v varchar2(100);
mycursor cursor is select item from item基表;
open mycursor;
fetch my cursor into item_v;
while not %notfoud
insert into 我的价格表(item,price)
select item,price from 价格表 where 价格表.item=item_v;
commit;
loop;
end; 

解决方案 »

  1.   

    oracle 的存储过程不能返回结果集,就是不能用 select * from x
    这种东西,如果你要返回结果集,就定义返回结果集的游标
      

  2.   

    declare
      item_v varchar2(100);
      cursor mycursor is 
      select item from item基表; 
    begin
      for rec in mycursor loop
         item_v:=rec.item;
         insert into 我的价格表(item,price)
         select item,price from 价格表 where 价格表.item=item_v;
         commit;
      end loop;
    end; 
    /
        
      

  3.   

    看过了,你的sql语法和逻辑应该没什么问题,问题可能出在别的地方:
    1、你的实际过程中可能有别的代码引起错误;
    2、你的插入目标表有其他不允许为空的字段或有的字段有非法插入约束或外键约束;
    仔细查一下吧,或者把全部代码贴上来