Oracle之数组
记忆力不好,提供样例套路:
固定长度数组:
declare
type t_test is varray(5) of varchar2(9);
test t_test := t_test('a', 'b', 'c', 'd', 'e');
begin
--遍历
for i in 1 .. test.count loop
dbms_output.put_line(test(i));
end loop;
end;
可变长度数组:
declare
type t_test is table of varchar2(9);
test t_test := t_test('a', 'b', 'c', 'd', 'e');
begin
--遍历
for i in 1 .. test.count loop
dbms_output.put_line(test(i));
end loop;
end;
自定义结果集:
如当前有表,表结构如图:

declare
type stu_record is record(
v_sname l_student_info_tbl.sname%type,
v_sage l_student_info_tbl.sage%type,
v_sgender l_student_info_tbl.sgender%type,
v_sclassno l_student_info_tbl.sclassno%type); TYPE stu_rec IS TABLE OF stu_record INDEX BY BINARY_INTEGER; v_stu_rec stu_rec; begin
select t.sname, t.sage, t.sgender, t.sclassno
bulk collect
into v_stu_rec
from l_student_info_tbl t; for i in 1 .. v_stu_rec.count loop
dbms_output.put_line(v_stu_rec(i).v_sname);
end loop;
end;
结果:注意:bulk collect 可以在select into ,fetch into ,returning into ,需要大量内存,但比游标高效。

%rowtype表示一行记录的变量,比分别使用%TYPE来定义表示表中各个列的变量要简洁得多,并且不容易遗漏、出错。这样会增加程序的可维护性。
declare
TYPE t_user IS TABLE OF l_student_info_tbl%ROWTYPE INDEX BY BINARY_INTEGER;
v_arry_user t_user; begin
select t.* bulk collect into v_arry_user from l_student_info_tbl t; for i in 1 .. v_arry_user.count loop
dbms_output.put_line(v_arry_user(i).sname);
end loop;
end;
有时批处理,用rowid处理更快高效。
declare
type t_rowid is table of rowid index by pls_integer;
v_rowid t_rowid; begin
select rowid
bulk collect
into v_rowid
from l_student_info_tbl t
where rownum <= 2; for i in 1 .. v_rowid.count loop
dbms_output.put_line(v_rowid(i));
end loop; forall i in 1.. v_rowid.last
--dml语句(insert update delete) end;
Oracle之数组的更多相关文章
- oracle 的数组(转)
declare type t_indexby is table of number index by binary_integer; type t_nested is table of number; ...
- oracle 之 数组、嵌套表、SQL查询式 实现多表数据for循环插入指定表
1.基础环境 创建基础表: CREATE TABLE TEST_TAB1( ID INT, NAME VARCHAR2(20) ); CREATE TABLE TEST_TAB2( ID INT, N ...
- 数组做为参数传入Oracle存储过程操作数据库
p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 120%; text-align: justi ...
- 通过数组方式向Oracle大批量插入数据(10万条11秒)
1.创建数据库Person CREATE TABLE Person( id number, name nvarchar2() , age number , sex nvarchar2() , pass ...
- MySQL与Oracle 差异比较之七其它
其它 编号 类别 ORACLE MYSQL 注释 1 内连接的更改 1.select a.*, b.*, c.*, d.* from a, b, c, d where a.id = b.id a ...
- Oracle Data Provider for .NET 的使用经验
原文:Oracle Data Provider for .NET 的使用经验 Oracle Data Provider for .NET 是Oracle提供的基于Ado.net接口的一个开发包. ...
- 对oracle用户创建asm磁盘
--root用户执行vi /etc/sysctl.conf #Install oracle settingfs.aio-max-nr = 1048576fs.file-max = 6815744#ke ...
- [ SHELL编程 ] 数组、关联数组和awk数组
本文主要对shell编程中常用的数组.关联数组和awk数组定义.操作以及注意事项做个总结,并提供具体案例. 数组 数组定义:一对圆括号表示数组,数组元素之间用空格符号分割. Array=(val1 v ...
- oracle 语句之对数据库的表名就行模糊查询,对查询结果进行遍历,依次获取每个表名结果中的每个字段(存储过程)
语句的执行环境是plsql的sql窗口, 语句的目的是从整个数据库中的所有表判断 不等于某个字段的记录数 . 代码如下: declare s_sql clob:=''; -- 声明一个变量,该变量用于 ...
随机推荐
- .NET Core 事件总线,分布式事务解决方案:CAP 基于Kafka
背景 相信前面几篇关于微服务的文章也介绍了那么多了,在构建微服务的过程中确实需要这么一个东西,即便不是在构建微服务,那么在构建分布式应用的过程中也会遇到分布式事务的问题,那么 CAP 就是在这样的背景 ...
- MYSQL.版本查看-LINUX
MYSQL.版本查看-LINUX 方式1: 不需登录mysql,登录Linux服务后,执行如下指令: # mysql -V 注意: 那个是大写的V,如果使用小写的v,在root没有设置密码的情况下,就 ...
- php中双$符 及一些基础知识
双$$符号表示可变变量 如 $a = "b", $b = 'c'; echo $$a 此时 $$a=>$($a) =>$b 输出的值就应该为c; 变量传应用值$b ...
- Python模拟ICMP包
主要使用Scapy来完成 基础环境 VM1(192.168.1.226) | | VM2(192.168.1.125) vm1封装icmp包发给vm2 vm1脚本: #! /usr/bin/env p ...
- 第一个Spring程序HelloWorld
对于初学者而言,任何理论化的讲解都比不上一个简单的HelloWorld,我们在学习Spring时也不外乎用最简单的HelloWorld程序来将这个灵活而又强大的轻量级框架推送到诸位面前.想要说明的是现 ...
- 劳德巴赫下载kernel和文件系统时问题
用劳德巴赫下载 kernel dtb rootfs BOOT.bin 报错(记了个大概) Bad CRC Ramdisk image is corrupt or invalid 记得之前有人和我说r ...
- latch
signal definition sequence:
- k8s基本对象及架构
一.基本对象 pod pod是最小的部署单元,一个pod由一个或多个容器组成,pod中的容器共享存储和网络,在同一台docker主机上运行. service service是一个应用服务的抽象,定义了 ...
- dataguard从库移动数据文件
------------方法1从库移动数据文件路径方法1--------------将表空间offline的方法不行 1.退出日志应用alter database recover managed st ...
- springboot使用validation 插件做数据校验
不多说废话. 首先,我们需要在入参实体对象中,使用注解,控制 @Datapublic class UpdateShufflingRequest { private String shuffling_l ...