Home > Database > Mysql Tutorial > Oracle type/rowtype/record

Oracle type/rowtype/record

WBOY
Release: 2016-06-07 15:20:01
Original
1217 people have browsed it

RECORD: 记录类型,可以理解为是几列数据的集合,使用的时候注意结果集只能有一行 ,引用时使用.来引用内部元素 declare type v_my_record is record (v_ename emp.ename%type, v_job emp.job%type); v_dname dept.dname%type; v_my v_my_record; --需要先定

RECORD: 记录类型,可以理解为是几列数据的集合,使用的时候注意结果集只能有一行

,引用时使用.来引用内部元素

declare type v_my_record is record

        (v_ename emp.ename%type, 
         v_job   emp.job%type);
v_dname dept.dname%type;
v_my v_my_record;   --需要先定义type  再声明变量
begin
v_dname:=&dname;
select ename,job into v_my
from emp inner join dept 
on emp.deptno=dept.deptno 
where upper(dept.dname)=upper(v_dname) and rownum=1;
dbms_output.put_line(v_my.v_ename||' '||v_my.v_job);
exception when no_data_found then
dbms_output.put_line('nononono..');

end;

ROWTYPE:可以理解为是几列数据的集合,可以对表、视图使用,应用的时候使用 "." 和record类似:

create or replace view v_emp 
as 
select ename,dname,empno 
from emp,dept 
where emp.deptno=dept.deptno;

--使用视图%rowtype
declare 
v_row v_emp%rowtype;
v_empno emp.empno%type;
begin
v_empno := &请输入编号;
select * into v_row from v_emp where empno= v_empno;
dbms_output.put_line(v_row.ename||','||v_row.dname);
end;


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template