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:=''; -- 声明一个变量,该变量用于 ...
随机推荐
- Xamarin.Forms 开发资源集合
收集整理了下 Xamarin.Forms 的学习参考资料,分享给大家,稍后会不断补充: UI样式 Snppts: Xamarin Forms UI Snippets. Prebuilt Templat ...
- 中国省市区json数据 三级联动
<label> <span>购买地址</span> <select name="PurchaseProvince" style=" ...
- Linux之文件权限
在Linux系统中,root用户基本对于每个文件都有可操作性,但是普通用户可能只能查看特定的文件,这是因为文件存在的权限机制,初步掌握文件的基本权限就操作可以对一些系统文件或者自定义文件有一个操作空间 ...
- CSRF原理
全称跨站伪造
- Setting NLS_LANG Value for Oracle
Introduction Many times, when you have an Oracle application and you have to support special charact ...
- 指定时间生成cron表达式
public class CronUtils { private static final SimpleDateFormat sdf = new SimpleDateFormat("ss m ...
- 线段树 HDU-1754 I Hate It
附上原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某 ...
- Kettle使用MySQL作为资源库报错解决方法
使用Kettle5.0.1,安装的是MySQL5.1.JDK1.6,在\data-integration\lib目录里添加mysql的JDBC包mysql-connector-java-5.0.8-b ...
- 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups)VALUES('1','hh','hh@163.com','Boss')' at line 1
mysql8.0版本 在已存在的表里插入一条数据 insert INTO api_user(id,username,email,groups)VALUES('1','hh','hh@163.com', ...
- vue打包app嵌入h5,区分app进入和android,ios显示不同的下载链接
vue打包app嵌入h5,区分app进入和android,ios显示不同的下载链接 需求:自己app打开的登录页面不显示app下载链接.其他地方打开判断android手机的跳转到android下载页链 ...