执行2个循环以在SQL中插入值

执行2个循环以在SQL中插入值,sql,oracle,loops,plsql,Sql,Oracle,Loops,Plsql,我使用一个过程从一个名为Datastream的表中获取数据,该表有1000行,我必须在一个游标中读取100条记录。对于每个记录,在表Masterdata中将主键与外键匹配,并在多个表中移动所有匹配的记录。然后,函数应该从表中获取接下来的100条记录,并执行相同的操作。 我需要使用两个循环作为条件 我被这个错误缠住了: ORA-01722:无效号码 编辑1:解决了上述错误,“产品id”的表数据类型与预期的不同 新错误:一切正常,过程运行,但我的表没有被insert查询填充。输出行打印SupID和P

我使用一个过程从一个名为Datastream的表中获取数据,该表有1000行,我必须在一个游标中读取100条记录。对于每个记录,在表Masterdata中将主键与外键匹配,并在多个表中移动所有匹配的记录。然后,函数应该从表中获取接下来的100条记录,并执行相同的操作。
我需要使用两个循环作为条件

我被这个错误缠住了:

ORA-01722:无效号码

编辑1:解决了上述错误,“产品id”的表数据类型与预期的不同

新错误:一切正常,过程运行,但我的表没有被insert查询填充。输出行打印SupID和PName

我正在使用以下代码:


create or replace procedure newting is
s integer := 1;
e integer := s+99;
total_S integer := 1; 

    cursor endCount is 
    select datastream_id, ROW_NUMBER() OVER ( ORDER BY datastream_id )
    from datastream
    where datastream_id <= (select (count(*)/100) from datastream);

    cursor transC is 
    SELECT datastream_id, product_id, customer_id, customer_name, outlet_id, outlet_name, quantity_sold, d_date
    from datastream
    where datastream_id between s and e
    order by datastream_id;

TYPE val1 IS TABLE OF datastream.datastream_id%type;
v1 val1;
TYPE val2 IS TABLE OF datastream.product_id%type;
v2 val2;
TYPE val3 IS TABLE OF datastream.customer_id%type;
v3 val3;
TYPE val8 IS TABLE OF datastream.d_date%type;
v8 val8;


PName masterdata.product_name%TYPE;
SupID masterdata.supplier_id%TYPE;
SName masterdata.supplier_name%TYPE;
PPrice masterdata.sale_price%TYPE;

begin
    
    open endCount;
    open transC;
    fetch transC bulk collect into v1,v2,v3,v4,v5,v6,v7,v8;
    close endCount;
    close transC;
    
    for x in endCount
    loop
        for y in v1.first .. v1.last
        loop
            
            
        select product_name, supplier_id, supplier_name, sale_price into PName, SupID, SName, PPrice
        from masterdata m
        where m.product_id=v2(y);   
        Dbms_output.put_line(SupID);  
            
        insert into product (product_id, product_name) select v2(y), PName from dual --error in this line
        where not exists (select * from product where product_id=v2(y));    
        
        insert into customer (customer_id, customer_name) select v3(y), v4(y) from dual
        where not exists (select * from customer
                where customer_id=v3(y));
        
        insert into d_time (d_date, d_year, d_month, d_day) 
        select v8(y), to_char(v8(y),'YY'), to_char(v8(y),'MM'), to_char(v8(y),'DD') 
        from dual
        where not exists (select * from d_time
                where d_date=v8(y));
        
        total_S := v7(y) * PPrice;
        
        insert into sales_fact (transaction_id, product_id, supplier_id, outlet_id, customer_id, d_date, quantity, price, total_sales)
        select v1(y), v2(y), SupID, v5(y), v3(y), v8(y), v7(y), PPrice, total_S
        from dual
        where not exists (select * from sales_fact
                where transaction_id = v1(y));    
            
        end loop;
        s:=s+99;
        e:=e+99;
    end loop;
end; 


创建或替换过程newting正在运行
s整数:=1;
e整数:=s+99;
总整数:=1;
游标结束计数为
选择数据流\u id,行号()超过(按数据流\u id排序)
从数据流

其中datastream_id当您尝试将字符串转换为数字时,可能会出现ORA-01722错误,基本上消息是字符串无法转换为数字。检查所有DML(插入),特别是日期。我的建议是注释所有(插入),但一个除外,尝试运行它,如果没有问题,那么继续第二个,直到找到问题并修复它(分而治之)。另外(只是一个观察),我相信“提交”超出了这个过程的范围,对吗

希望这能有所帮助