你好,我正在尝试使此插入物变大,但它不起作用,甚至没有向我抛出一些错误或警告
idproduct,precio和fkproovedor变量是从另一个表中获取的
DECLARE
RAN_PRODUCT NUMBER;
RAN_CANT NUMBER;
NVENTA NUMBER;
MVENTA NUMBER;
MT NUMBER;
BEGIN
SELECT MIN (IDVENTA) INTO NVENTA FROM marcos.VENTA;
SELECT COUNT (IDVENTA) INTO MVENTA FROM MARCOS.VENTA;
FOR loop_one IN 1 .. 10
LOOP
FOR loop_TWO IN 1 .. 2
LOOP
SELECT (1 + ABS (MOD (DBMS_RANDOM.random, 50)))
INTO RAN_PRODUCT
FROM DUAL;
SELECT (1+ABS(MOD(dbms_random.random,10)))
INTO RAN_CANT
FROM DUAL;
INSERT INTO marcos.DETALLEVENTA
SELECT SEQ_DTEVENTA.NEXTVAL AS IDDETAVENTA,
PRECIO AS PRECIO,
RAN_CANT AS CANTIDAD,
RAN_PRODUCT AS FKPRODUCTO,
FKPROOVEDOR AS FKPROVEEDOR,
NVENTA AS FKVENTA
FROM MARCOS.PRODUCTO
WHERE IDPRODUCTO = RAN_PRODUCT;
END LOOP;
NVENTA := NVENTA + 1;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Se ha producido un error');
ROLLBACK;
END;
答案 0 :(得分:1)
使用简单的INSERT ... SELECT语句代替PL / SQL代码,像这样
INSERT INTO DETALLEVENTA( IDDETAVENTA,PRECIO,CANTIDAD,FKPRODUCTO,FKPROVEEDOR,FKVENTA )
SELECT SEQ_DTEVENTA.NEXTVAL AS IDDETAVENTA,
PRECIO AS PRECIO,
RAN_CANT AS CANTIDAD,
RAN_PRODUCT AS FKPRODUCTO,
FKPROOVEDOR AS FKPROVEEDOR,
(SELECT MIN (IDVENTA) FROM marcos.VENTA) AS FKVENTA
FROM PRODUCTO p
JOIN (
SELECT (1 + ABS (MOD (DBMS_RANDOM.random, 50))) as RAN_PRODUCT,
(1+ABS(MOD(dbms_random.random,10))) as RAN_CANT
FROM (
select 1 from dual connect by level <= 10 * 2
)
) x
ON p.IDPRODUCTO = x.RAN_PRODUCT