记忆力不好,提供样例套路:

固定长度数组:

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之数组的更多相关文章

  1. oracle 的数组(转)

    declare type t_indexby is table of number index by binary_integer; type t_nested is table of number; ...

  2. oracle 之 数组、嵌套表、SQL查询式 实现多表数据for循环插入指定表

    1.基础环境 创建基础表: CREATE TABLE TEST_TAB1( ID INT, NAME VARCHAR2(20) ); CREATE TABLE TEST_TAB2( ID INT, N ...

  3. 数组做为参数传入Oracle存储过程操作数据库

    p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 120%; text-align: justi ...

  4. 通过数组方式向Oracle大批量插入数据(10万条11秒)

    1.创建数据库Person CREATE TABLE Person( id number, name nvarchar2() , age number , sex nvarchar2() , pass ...

  5. MySQL与Oracle 差异比较之七其它

    其它 编号 类别 ORACLE MYSQL 注释 1 内连接的更改 1.select a.*, b.*, c.*, d.*  from a, b, c, d where a.id = b.id   a ...

  6. Oracle Data Provider for .NET 的使用经验

    原文:Oracle Data Provider for .NET 的使用经验 Oracle Data Provider for .NET 是Oracle提供的基于Ado.net接口的一个开发包.    ...

  7. 对oracle用户创建asm磁盘

    --root用户执行vi /etc/sysctl.conf #Install oracle settingfs.aio-max-nr = 1048576fs.file-max = 6815744#ke ...

  8. [ SHELL编程 ] 数组、关联数组和awk数组

    本文主要对shell编程中常用的数组.关联数组和awk数组定义.操作以及注意事项做个总结,并提供具体案例. 数组 数组定义:一对圆括号表示数组,数组元素之间用空格符号分割. Array=(val1 v ...

  9. oracle 语句之对数据库的表名就行模糊查询,对查询结果进行遍历,依次获取每个表名结果中的每个字段(存储过程)

    语句的执行环境是plsql的sql窗口, 语句的目的是从整个数据库中的所有表判断 不等于某个字段的记录数 . 代码如下: declare s_sql clob:=''; -- 声明一个变量,该变量用于 ...

随机推荐

  1. python的高级数组之稀疏矩阵

    稀疏矩阵的定义: 具有少量非零项的矩阵(在矩阵中,若数值0的元素数目远多于非0元素的数目,并且非0元素分布没有规律时,)则称该矩阵为稀疏矩阵:相反,为稠密矩阵.非零元素的总数比上矩阵所有元素的总数为矩 ...

  2. requests 获取百度推广信息

    2019年的第一篇博客,恩,好久没写过博客了,恩,忘了,哈哈,实在是太懒了 今天写一个爬取百度推广数据的爬虫,当然我写的肯定不是那么的完美,但是能用,大哭 注意:有的时候,get或post方法获取数据 ...

  3. VS工具箱中添加DevExpress控件

    关闭所有VS进程: ①使用控制台进入DevExpress安装目录: D:\DevExpress\Components\Tools\ ②添加DevExpress控件:ToolboxCreator.exe ...

  4. Wed Sep 19 20:48:46 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection mus

    Wed Sep 19 20:48:46 CST 2018 WARN: Establishing SSL connection without server's identity verificatio ...

  5. Liunx系统升级自带的Python版本

    一.查看系统信息 [root@localhost ~]# cat /etc/redhat-release CentOS release 6.4 (Final) [root@localhost ~]# ...

  6. Linq高级查询,分页查询及查询分页结合

    一.高级查询与分页查询 1.以...开头    StartsWith Repeater1.DataSource=con.Users.Where(r=>r.Nickname.StartsWith( ...

  7. (Review cs231n) CNN in Practice

    Make the most of your data Data augmentation 加载图像后,对图像做一些变化,这些变换不改变图像的标签. 通过各种变换人为的增大数据集,可以避免过拟合提高模型 ...

  8. Let'sEncrypt 免费通配符/泛域名SSL证书添加使用教程

    Let'sEncrypt 免费通配符/泛域名SSL证书添加使用教程 通配符证书一般还是比较贵的一般最便宜的通配符证书5.60美元一年,只不过Let'sEncrypt的有效期是3个月,对于一般用户来说基 ...

  9. LDAP&IMPLEMENTATION

    LDAP是轻量目录访问协议,英文全称是LIGHTWEIGHT DIRECTORY ACCESS PROTOCOL,一般都简称为LDAPLDAP的特点1.LDAP 是一种网络协议而不是数据库,而且LDA ...

  10. h5页面在ios机上禁止长按复制

    (注意,增加之后需要对input的另外设置,不然输入框无法输入)场景:H5出现一个按钮需要长按几秒展示动画的,如:skcs.net-tactic.com/wap/peace/index,这时就需要用到 ...