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

固定长度数组:

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. Nuxt 自动化部署及打包后文件自动上传七牛云

    1.安装七牛云 2.在项目根目录新建 upload.js 3.上传凭证 4.上传配置,详情参考七牛云文档 5.在 package.js中修改项目build完成执行upload文件命令 7. nuxt. ...

  2. live Templates 活动模板. 配置完之后,就可以快速编码-代码块

    配置:live Templates 活动模板. 配置完之后,就可以快速编码-代码块. 输入startflask敲回车:   就会生成代码:   怎么做到的呢? 如下:   注意第七步: 原本不是cha ...

  3. Python:re中的group方法简介

    原文地址:http://www.cnblogs.com/kaituorensheng/archive/2012/08/20/2648209.html. 正则表达式中,group()用来提出分组截获的字 ...

  4. Linux 命令整理-ps

    ps 命令 ps -ef | grep tomcat ps -ef :以长格式(全格式)显示所有进程:“|” :是管道grep :检索tomcat :与字符tomcat有关的进程 ps[选项]-e:显 ...

  5. python练习--利用while循环和if语句,完成猜骰子的数字大小

    #exampleimport random# 骰子投掷的随机叔numnum = random.randint(1,6)# 输入一个猜测的数字temp = input("请输入一个整数:&qu ...

  6. pytorch使用不完全文档

    1. 利用tensorboard看loss: tensorflow和pytorch环境是好的的话,链接中的logger.py拉到自己的工程里,train.py里添加相应代码,直接能用. 关于环境,小小 ...

  7. shell脚本的一些常用操作

    字符串长度: ${#string}可获取string字符串的长度,如下: jenkins@soft1pc:~$ str="who are you"jenkins@soft1pc:~ ...

  8. git 使用过程中遇到的问题does not appear to be a git repository Could not read from remote respository

    想把本地的git库上传到github上.github已经新建了一个public仓库,利用网站的命令 git Bash报错:does not appear to be a git repository  ...

  9. JVM探秘6--图解虚拟机栈的局部变量表和操作数栈工作流程

    案例代码如下: public class JVMTest { public static Integer num = 10; public int add(int i){ int j = 5; int ...

  10. 服务器怎么安装mysql数据库

    有些小伙伴们想自己玩玩服务器.可以买了服务以后,发现服务器就是一个大框子,没有数据存储.啥都没有,这时候就需要各种软件操作来逐步安装这些东西, 一.使用的工具:xshell(从官网上下载),目的是得使 ...