我想以这种方式在表中插入数据,这样每当命令运行时,就会输入不同的数据.比如。
create table oppo
(
name varchar(10),
class varchar(10),
roll number (5)
);
declare
s number;
i number;
n char(10);
c char(10);
r number;
begin
s:=:no_of_records;
for i in 1..s LOOP
n:=:Enter_Name;
c:=:Enter_Class;
r:=:Enter_Roll;
insert into oppo (name,class,roll) values (n,c,r);
END LOOP;
End;
当我运行程序,并输入no_of_records(5或任何数字),并输入姓名和其他数据。结果同样的数据显示了5次(或输入记录的次数)。我想每5次输入唯一的数据。
PLSQL程序不是 互动式. 如果你想插入不同的值,用一个存储过程替换这个匿名的PLSQL块,并尽可能多地运行它,每次都提供新的值。
例如
SQL> create table test (name varchar2(20), class number);
Table created.
SQL> create or replace procedure p_test (par_name in varchar2, par_class in number) as
2 begin
3 insert into test (name, class) values (par_name, par_class);
4 end;
5 /
Procedure created.
SQL> exec p_test('&name', &class);
Enter value for name: LF
Enter value for class: 1
PL/SQL procedure successfully completed.
SQL> exec p_test('&name', &class);
Enter value for name: Bigfoot
Enter value for class: 2
PL/SQL procedure successfully completed.
SQL> exec p_test('&name', &class);
Enter value for name: Scott
Enter value for class: 3
PL/SQL procedure successfully completed.
SQL> select * From test;
NAME CLASS
-------------------- ----------
LF 1
Bigfoot 2
Scott 3
SQL>