Oracle 学习(3)

记录类型:
declare type sturecord is record(
       name student.name%type,
       sex student.sex%type,
       stuno student.stuno%type
);      
      onestu sturecord;
   begin 
     select name,sex,stuno into onestu from student where stuno=1;
     dbms_output.put_line(onestu.name||'  '||onestu.sex||'                                 '||onestu.stuno);
end;

表类型:
declare onestu student%rowType;
     begin
        select * into onestu from student where stuno=2;
        dbms_output.put_line(onestu.stuno||'  '||onestu.name);
     end;


PL/SQL 表
declare
   type emp_type is table of EMP%rowtype index by binary_integer;
   emps emp_type;   --声明表类型变量
begin
   emps(1).empno :=1001;
   emps(1).ename :='JACK';
   emps(1).sal :=3200 ;
   dbms_output.put_line(emps(1).ename);
end;


PL/SQL游标:

declare
cursor cur_emp is  select * from emp where sal< 2000 order by sal desc; --声明游标
oneemp EMP%rowtype;      --声明表纪录类型
begin
open cur_emp;          --打开游标
dbms_output.put_line('编号   姓名   年龄 ');  
loop
fetch cur_emp into oneemp;   --提取游标
dbms_output.put_line(oneemp.empno||'  '||oneemp.ename||'  '||oneemp.sal);
exit when cur_emp%notfound;
end loop;
if cur_emp%isopen then
   dbms_output.put_line('游标还开着呢。。。');
else
   dbms_output.put_line('游标关着了。。。。');
end if;

dbms_output.put_line('总共  '||cur_emp%rowcount||'  行');
close cur_emp; --关闭游标
end;

 

你可能感兴趣的:(oracle,sql)