PL/Sql记录,集合,记录表的使用

为了处理单行单列的数据,开发人员可以使用标量变量;为了处理单行多列的数据,开发人员可以使用PL/SQL记录 ;而为了处理单列多行数据,开发人员可以使用PL/SQL集合。
记录表处理多行多列。

记录的使用

declare
type emp_record is record(
name t_emp.ename%type,  #声明标题变量
salary t_emp.sal%type,
dno t_emp.depno%type

);
emp_record_type emp_record;#声明记录变量
begin
select ename,sal,deptno into emp_record_type
from t_emp where empno=&no;
   dbms_output.put_line('雇员姓名:'||emp_record.name);


end


create table t_dept as
select * from dept;



declare
dept_record dept%rowtype;--列的列名、数据类型都相同的行记录变量
begin
   dept_record.deptno :=50;
   dept_record.loc:='beijing';
   dept_record.dname:='admin';
   insert into t_dept values dept_record;
   ---这个也可以
    update t_dept set row=dept_record
   where deptno=50;
   commit;
   commit;

记录表的使用:
将emp表中数据全部查询出来存放到PL/SQL记录表中。

declare
cursor c_emp is select * from emp;
type emp_table_type is table of emp%rowtype
index by binary_integer;
emp_table emp_table_type;
counter number(20):=0;
begin
  for e in c_emp loop
    counter :=counter+1;
    emp_table(counter):=e;
    dbms_output.put_line(emp_table(counter).ename||' ,'||emp_table(counter).sal);
    end loop;
 end;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

有时间指导毕业设计

觉得写的好的话可以给我打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值