首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

PL/sql 学习札记备忘一

2012-07-08 
PL/sql 学习笔记备忘一?record--定义数据记录的类型declaretype emp_recordis record(v_ename emp.ename%t

PL/sql 学习笔记备忘一

?

record--定义数据记录的类型declare  type emp_record  is record(       v_ename emp.ename%type,       v_sal   emp.sal%type,       v_deptno emp.deptno%type  );  v_ename_record emp_record;begin  select ename,sal,deptno into v_ename_record from emp where empno=7369;  v_ename_record.v_ename:='zhangsan';    dbms_output.put_line(v_ename_record.v_ename);  dbms_output.put_line(v_ename_record.v_sal);  dbms_output.put_line(v_ename_record.v_deptno);end;--集合容器index_by table ,索引表,嵌套表varray当行当列   变量varcher2 %type当行多列   Record当列多行   集合(%type)多行多列   集合(%rowtype)索引表typw name IS TABLE OF element_type index by  key_type;declare     type num_array is table of number(5) index by binary_integer;     a num_array;begin  for i in 1..10 loop    a(i):=i;  end loop;         for i in 1..10 loop    dbms_output.put_line(a(i));  end loop;end;declare  type emp_array is table of emp%rowtype index by binary_integer;  a emp_array;begin  select * bulk collect into a from emp;  for i in a.first..a.last loop      dbms_output.put_line(a(i).ename||' '||a(i).job);  end loop;end;--record 嵌套Recorddeclare          type record1 is record(              vename emp.ename%type,              vempno emp.empno%type,              vsal   emp.sal%type                  );         type record2 is record(              v1 number(5),              v2 varchar2(20),              v3 record1         );         type record1_array is table of record1 index by binary_integer;         a record1;         b record2;         c record1_array;         begin         select ename,empno,sal into a from emp where empno=7369;         b.v3:=a;          dbms_output.put_line(b.v3.vename);          dbms_output.put_line(b.v3.vempno);          dbms_output.put_line(b.v3.vsal);end;declare    type yy is table of varchar2(20) index by varchar2(20);    a yy;begin    a('beijing'):='china';    a('dongjing'):='japan';    a('huashengduan'):='usa';    dbms_output.put_line(a('beijing'));    end;

热点排行