DML 操作中,可以直接使用记录,来简化我们的编码。
1. insert
SQL> select * from test1;
A B
-------------------- ----------
test1 99
test1 1010
test1 1111
test1 1212
test1 1313
SQL> declare
2 rec_test1 test1%rowtype;
3 begin
4 rec_test1.a := 'yuechaotian';
5 rec_test1.b := '8888';
6 insert into test1 values rec_test1;
7 commit;
8 end;
9 /
PL/SQL 过程已成功完成。
SQL> select * from test1;
A B
-------------------- ----------
test1 99
test1 1010
test1 1111
test1 1212
test1 1313
yuechaotian 8888
已选择6行。
在 forall 中也可以这样使用。
2. upate
SQL> declare
2 rec_test1 test1%rowtype;
3 begin
4 rec_test1.a := 'tianyc';
5 rec_test1.b := '6666';
6 update test1
7 set row = rec_test1
8 where a = 'yuechaotian';
9 commit;
10 end;
11 /
PL/SQL 过程已成功完成。
SQL> select * from test1;
A B
-------------------- ----------
test1 99
test1 1010
test1 1111
test1 1212
test1 1313
tianyc 6666
已选择6行。
row 是关键字,表示更新整行