当要在 Oracle 中之心批量 INSERT、UPDATE 和 DELETE 操作时,可以使用 FORALL 语句。语法:
- --语法1:
- FORALL 下标变量(只能当作下标被引用) IN 下限..上限
- sql 语句; --只允许一条 sql 语句
-
-
- --语法2:
- FORALL 下标变量 IN INDICES OF(跳过没有赋值的元素,例如被 DELETE 的元素,NULL 也算值) 集合
- [BETWEEN 下限 AND 上限]
- sql 语句;
-
-
- --语法3:
- FORALL 下标变量 IN VALUES OF 集合(把该集合中的值当作下标变量)
- sql 语句;
- create table tb1(
- id number(5),
- name varchar2(50)
- );
语法1演示:
- --批量插入演示
- declare
- type tb_table_type is table of tb1%rowtype
- index by binary_integer;
- tb_table tb_table_type;
- begin
- for i in 1..10 loop
- tb_table(i).id:=i;
- tb_table(i).name:="NAME"||i;
- end loop;
- forall i in 1..tb_table.count
- insert into tb1 values tb_table(i);
- end;
-
-
- --批量修改演示
- declare
- type tb_table_type is table of tb1%rowtype
- index by binary_integer;
- tb_table tb_table_type;
- begin
- for i in 1..10 loop
- tb_table(i).id:=i;
- tb_table(i).name:="NAMES"||i;
- end loop;
- forall i in 1..tb_table.count
- update tb1 t set row = tb_table(i) where t.id = tb_table(i).id;
- end;
-
-
- --批量删除演示
- declare
- type tb_table_type is table of tb1%rowtype
- index by binary_integer;
- tb_table tb_table_type;
- begin
- for i in 1..10 loop
- tb_table(i).id:=i;
- tb_table(i).name:="NAMES"||i;
- end loop;
- forall i in 1..tb_table.count
- delete tb1 where id = tb_table(i).id;
- end;
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12Ubuntu 11.10下MySQL 5.5解压版本安装在Linux上Oracle如何启用异步IO?相关资讯 Oracle数据库基础教程
- 在Oracle数据库中插入含有&符号的 (03/06/2013 09:20:14)
- Oracle 执行计划更改导致数据加工 (02/13/2013 14:45:04)
- 判断Oracle Sequence是否存在 (02/13/2013 14:32:26)
| - Oracle数据库中无法对数据表进行 (02/26/2013 14:24:58)
- Oracle 在同一台主机上建立用户管 (02/13/2013 14:40:58)
- Oracle em 无法启动,报not found错 (02/13/2013 14:29:48)
|
本文评论 查看全部评论 (0)