您的位置:首页 > 数据库 > Oracle

oracle 中PL/SQL中type的简单用法

2012-11-27 22:32 453 查看
转自:http://hi.baidu.com/mangkata/item/d72531c26126eb5dbdef69f8
oracle 中PL/SQL中type的简单用法

1.参考系统的变量类型声明一个type

declare
type myrecord is record(id varchar2(10),names varchar2(10));
real_record myrecord;
begin
select EMPNO, ENAME into real_record from emp where empno='7369';
dbms_output.put_line(real_record.id||'   '||real_record.names);
end;

2.参考系统中存在的表的字段类型创建(其中emp表是SCOTT用户下的一张表)

declare
type myrecord is record(id emp.empno%type,names emp.ename%type);
real_record myrecord;
begin
select EMPNO, ENAME into real_record from emp where empno='7369';
dbms_output.put_line(real_record.id||'   '||real_record.names);
end;

3.完全参照一个表来创建

declare
myrec emp%rowtype;
begin
select * into myrec from emp where empno='7369';
dbms_output.put_line(myrec.empno||'   '||myrec.ename||'  '||myrec.job);
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: