我修改了你的代码,以便它可以工作。干得好。
表:
SQL> CREATE TABLE EquatA2 2 ( 3 dat1 NUMBER(2,0), 4 dat2 NUMBER(2,0), 5 sol NUMBER(6,3), 6 note VARCHAR2(20) 7 ); Table created. SQL>
PL / SQL匿名程序:
SQL> DECLARE 2 num1 EquatA2.dat1%TYPE; 3 num2 EquatA2.dat2%TYPE; 4 solution EquatA2.sol%TYPE; 5 notes EquatA2.note%TYPE; 6 BEGIN 7 delete from equata2; 8 FOR i IN 1..10 LOOP 9 num1 := ROUND(DBMS_RANDOM.VALUE(-4, +4), 0); 10 num2 := ROUND(DBMS_RANDOM.VALUE(-4, +4), 0); 11 -- DBMS_OUTPUT.PUT_LINE(num1); 12 -- DBMS_OUTPUT.PUT_LINE(num2); 13 14 IF num1 != 0 THEN 15 solution := -num2 / num1; 16 notes := 'solvable'; 17 ELSIF num1 = 0 AND num2 = 0 THEN 18 notes := 'indefinite'; 19 ELSIF num1 = 0 AND num2 != 0 20 THEN notes := 'impossible'; 21 END IF; 22 23 INSERT INTO EquatA2 VALUES (num1, num2, solution, notes); 24 END LOOP; 25 END; 26 / PL/SQL procedure successfully completed.
结果:
SQL> select * from equata2; DAT1 DAT2 SOL NOTE ---------- ---------- ---------- -------------------- 1 -4 4 solvable -1 0 0 solvable 0 3 0 impossible 0 2 0 impossible 0 0 0 indefinite 3 -1 ,333 solvable 4 3 -,75 solvable 1 -1 1 solvable -1 -2 -2 solvable 2 3 -1,5 solvable 10 rows selected. SQL>