Oracle数组入门
2010-05-08 18:02
183 查看
Oracle数组一般可以分为固定数组和可变数组
固定数组
Sql代码
declare
type v_ar is varray(10) of varchar2(30);
my_ar v_ar:=v_ar('g','m','d','龚','帅');
begin
for i in 1..my_ar.count
loop
dbms_output.put_line(my_ar(i));
end loop;
end;
declare
type v_ar is varray(10) of varchar2(30);
my_ar v_ar:=v_ar('g','m','d','龚','帅');
begin
for i in 1..my_ar.count
loop
dbms_output.put_line(my_ar(i));
end loop;
end;
可变数组
一维数组
Sql代码
declare
type v_table is table of varchar2(30) index by binary_integer;
--类型可以是前面的类型定义,index by binary_integer子句代表以符号整数为索引,
--这样访问表类型变量中的数据方法就是“表变量名(索引符号整数)”。
my_table v_table;
begin
for i in 1..20
loop
my_table(i):=i;
dbms_output.put_line(my_table(i));
end loop;
end;
declare
type v_table is table of varchar2(30) index by binary_integer;
--类型可以是前面的类型定义,index by binary_integer子句代表以符号整数为索引,
--这样访问表类型变量中的数据方法就是“表变量名(索引符号整数)”。
my_table v_table;
begin
for i in 1..20
loop
my_table(i):=i;
dbms_output.put_line(my_table(i));
end loop;
end;
多维数组--多条记录
Sql代码
declare
type v_table is table of t_user%rowtype index by binary_integer;
my_table v_table;
begin
select * bulk collect into my_table from t_user;
for i in 1..my_table.count/10 --my_table.count/10 取到的值为四舍五入值
loop
dbms_output.put_line('suser--'||my_table(i).suser);
dbms_output.put_line('name---'||my_table(i).name);
dbms_output.put_line('sex----'||my_table(i).sex);
end loop;
end;
declare
type v_table is table of t_user%rowtype index by binary_integer;
my_table v_table;
begin
select * bulk collect into my_table from t_user;
for i in 1..my_table.count/10 --my_table.count/10取到的值为四舍五入值
loop
dbms_output.put_line('suser--'||my_table(i).suser);
dbms_output.put_line('name---'||my_table(i).name);
dbms_output.put_line('sex----'||my_table(i).sex);
end loop;
end;
多维数组--单条记录
Sql代码
declare
type v_table is table of t_user%rowtype index by binary_integer;
my_table v_table;
begin
select * into my_table(9) from t_user where suser='admin';
--my_table(i) i可以为任意整数,但取值时必须保持以i一致;
dbms_output.put_line('--suser--'||my_table(9).suser||'--name--'||my_table(9).name);
end;
declare
type v_table is table of t_user%rowtype index by binary_integer;
my_table v_table;
begin
select * into my_table(9) from t_user where suser='admin';
--my_table(i) i可以为任意整数,但取值时必须保持以i一致;
dbms_output.put_line('--suser--'||my_table(9).suser||'--name--'||my_table(9).name);
end;
自定义数组
Sql代码
create or replace type varray_list as varray(30) of varchar2(50);
--使用自定义数组
create or replace procedure show_list(p_varlist in varray_list)
is
v_str varchar2(50);
begin
for i in 1..p_varlist.count
loop
v_str:=p_varlist(i);
dbms_output.put_line('v_str='||v_str);
dbms_output.put_line('p_varlist('||i||')='||p_varlist(i));
end loop;
end;
declare
my_var varray_list:=varray_list('g','m','d','龚','帅');
begin
show_list(my_var);
end;
固定数组
Sql代码
declare
type v_ar is varray(10) of varchar2(30);
my_ar v_ar:=v_ar('g','m','d','龚','帅');
begin
for i in 1..my_ar.count
loop
dbms_output.put_line(my_ar(i));
end loop;
end;
declare
type v_ar is varray(10) of varchar2(30);
my_ar v_ar:=v_ar('g','m','d','龚','帅');
begin
for i in 1..my_ar.count
loop
dbms_output.put_line(my_ar(i));
end loop;
end;
可变数组
一维数组
Sql代码
declare
type v_table is table of varchar2(30) index by binary_integer;
--类型可以是前面的类型定义,index by binary_integer子句代表以符号整数为索引,
--这样访问表类型变量中的数据方法就是“表变量名(索引符号整数)”。
my_table v_table;
begin
for i in 1..20
loop
my_table(i):=i;
dbms_output.put_line(my_table(i));
end loop;
end;
declare
type v_table is table of varchar2(30) index by binary_integer;
--类型可以是前面的类型定义,index by binary_integer子句代表以符号整数为索引,
--这样访问表类型变量中的数据方法就是“表变量名(索引符号整数)”。
my_table v_table;
begin
for i in 1..20
loop
my_table(i):=i;
dbms_output.put_line(my_table(i));
end loop;
end;
多维数组--多条记录
Sql代码
declare
type v_table is table of t_user%rowtype index by binary_integer;
my_table v_table;
begin
select * bulk collect into my_table from t_user;
for i in 1..my_table.count/10 --my_table.count/10 取到的值为四舍五入值
loop
dbms_output.put_line('suser--'||my_table(i).suser);
dbms_output.put_line('name---'||my_table(i).name);
dbms_output.put_line('sex----'||my_table(i).sex);
end loop;
end;
declare
type v_table is table of t_user%rowtype index by binary_integer;
my_table v_table;
begin
select * bulk collect into my_table from t_user;
for i in 1..my_table.count/10 --my_table.count/10取到的值为四舍五入值
loop
dbms_output.put_line('suser--'||my_table(i).suser);
dbms_output.put_line('name---'||my_table(i).name);
dbms_output.put_line('sex----'||my_table(i).sex);
end loop;
end;
多维数组--单条记录
Sql代码
declare
type v_table is table of t_user%rowtype index by binary_integer;
my_table v_table;
begin
select * into my_table(9) from t_user where suser='admin';
--my_table(i) i可以为任意整数,但取值时必须保持以i一致;
dbms_output.put_line('--suser--'||my_table(9).suser||'--name--'||my_table(9).name);
end;
declare
type v_table is table of t_user%rowtype index by binary_integer;
my_table v_table;
begin
select * into my_table(9) from t_user where suser='admin';
--my_table(i) i可以为任意整数,但取值时必须保持以i一致;
dbms_output.put_line('--suser--'||my_table(9).suser||'--name--'||my_table(9).name);
end;
自定义数组
Sql代码
create or replace type varray_list as varray(30) of varchar2(50);
--使用自定义数组
create or replace procedure show_list(p_varlist in varray_list)
is
v_str varchar2(50);
begin
for i in 1..p_varlist.count
loop
v_str:=p_varlist(i);
dbms_output.put_line('v_str='||v_str);
dbms_output.put_line('p_varlist('||i||')='||p_varlist(i));
end loop;
end;
declare
my_var varray_list:=varray_list('g','m','d','龚','帅');
begin
show_list(my_var);
end;
相关文章推荐
- oracle pl/sql 入门+ 数组使用+游标+动态SQL
- oracle pl/sql 入门+ 数组使用+游标+动态SQL
- 树状数组入门
- Oracle-存储过程-参数为数组-返回值为集合,java-调用存储过程
- ORACLE入门之简析REDO LOGFILE
- oracle入门之第一章【简单查询语句】
- Binary Indexted Tree 树状数组入门
- 在Oracle中使用字符串数组参数
- C#新手入门代码 LINQ 一个int型数组找到其中小于指定数的成员
- oracle PL/SQL入门--创建表
- Oracle PL/SQL入门语法点
- iBatis简单入门教程(oracle)
- oracle入门的好书&一些有用的网站
- Oracle的入门心得
- oracle入门之第二章【限制性查询和数据的排序】
- hdu 1166 树状数组 线段树入门
- Oracle的入门心得
- java 从零开始,学习笔记之基础入门<Oracle_基础>(三十三)
- oracle 字符串转数组的函数
- PHP入门(二)数组 关联数组