Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1693674
  • 博文数量: 136
  • 博客积分: 10021
  • 博客等级: 上将
  • 技术积分: 3261
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-22 11:26
文章分类

全部博文(136)

文章存档

2010年(1)

2009年(26)

2008年(109)

我的朋友

分类: Oracle

2008-06-07 17:10:11

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 是关键字,表示更新整行。
阅读(1211) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~