oracle数组学习资料

mac2022-06-30  97

--oracle数组,所谓数组就是  字段的 个数,数组应该很有用--可变数组 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_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 scott.emp%rowtype index by binary_integer;  my_table v_table;begin  select * bulk collect into my_table from scott.emp;  for i in 1 .. my_table.count --my_table.count/10取到的值为四舍五入值     loop    dbms_output.put('Line' || i || chr(9) || 'empno--' || my_table(i)                    .empno || chr(9));    dbms_output.put_line('ename---' || my_table(i).ename);    end loop;end;--多维数组--单条记录declare  type v_table is table of scott.emp%rowtype index by binary_integer;  my_table v_table;begin  select * into my_table(9) from t_user where empuser = 'SMITH';  --my_table(i) i可以为任意整数,但取值时必须保持一致;    dbms_output.put_line('--suser--' || my_table(9).suser || '--name--' || my_table(9).name);end;

转载于:https://www.cnblogs.com/iyoume2008/p/5633328.html

相关资源:Oracle 数组的学习 小知识也要积累,养成好的学习态度
最新回复(0)