首页 > 数据库技术 > 详细

PL/SQL 记录 Record 简介

时间:2014-06-07 06:10:56      阅读:359      评论:0      收藏:0      [点我收藏+]
记录类型是表中当行数据结构的一个镜像。每个记录只存储一行数据,记录包含的是字段,而不是列。
bubuko.com,布布扣
1.用%rowtype属性隐式定义记录类型
bubuko.com,布布扣
declare
    individual individuals%rowtype   --记录变量individual与individuals表的结构构成镜像,拥有表的所有字段
begin
    individual.individual_id:=1;     --对变量的各个字段初始化
    individual_id.first_name:=Jone;
    individual_id.last_name:=Steve;

    insert
    into individuals                --将字段插入到individuals表中
    vaules
    (individual.individual_id,
    individual_id.first_name,
    individual_id.last_name);

    commit;
    end;
    /
bubuko.com,布布扣
bubuko.com,布布扣

 

bubuko.com,布布扣
2.显式的将记录定义为PL/SQL记录类型
bubuko.com,布布扣
declare
    type individual_record is record  --显shi的定义记录类型 individual_record
    (individual_id integer,
     first_name varchar(30 char),
     last_name varchar(30 char)
     );
begin
     individual  individual_record;   --定义 individual_record的一个变量 individual
     individual.individual_id:=1;     --对变量的各个字段初始化
     individual_id.first_name:=Jone;
     individual_id.last_name:=Steve;
     
    insert into
    individuals                --将字段插入到individuals表中
    vaules
    (individual.individual_id,
    individual_id.first_name,
    individual_id.last_name);
commit
end;
/
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
3.显式的将记录类型定义为对象类型
bubuko.com,布布扣
--create a database object type
create or replace type individual_record as object  --对象类型头
(
    individual_id interger,
    first_name varchar(30 char),
    last_name varchar(30 char),

    constructor function individual_record
    (
        individual_id interger,
        first_name varchar,
        last_name varchar
    )
    return self as result
)
instantiable not final;
/

--crate a database object body                  --对象主体
create or replace type body individual_record as
    constructor function individual_record
    (
        individual_id interger,
        first_name varchar,
        last_name varchar
    )
    return self as result is                 --构造函数实现
    begin
        self.individual_id:=individual_id;
        self.first_name:=first_name;
        selg.last_name:=last_name;
        return;
    end;
end;
/


declare
    individual individual_record;        --用对象类型定义individual记录变量
begin
    individual:=
        individual(1,Jone,Steve);     --调用构造函数初始化记录变量

    insert into
    individuals                --将字段插入到individuals表中
    vaules
    (individual.individual_id,
    individual_id.first_name,
    individual_id.last_name);

    commit;
end;
/
bubuko.com,布布扣
bubuko.com,布布扣

 

PL/SQL 记录 Record 简介,布布扣,bubuko.com

PL/SQL 记录 Record 简介

原文:http://www.cnblogs.com/qianwen/p/3770442.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!