PL/SQL学习笔记五
游标是从数据库中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向首记录, 利用fetch语句移动该指针,从而对游标中的数据进行各种操作。
1.定义游标
cursor 游标名 is select语句;
2.打开游标
open 游标名;
3.提取游标数据
fetch 游标名 into 变量名1, 变量名2, ....;
或
fetch 游标名 into 记录型变量名;
4.关闭游标
close 游标名;
5.游标的属性
%isopen
该属性标识游标是否打开,如果没有打开游标就使用fetch语句将提示错误。
%isfound
该属性标识一个fetch语句是否有值,有值返回true,否则返回false。
%notfound
该属性与%isfound相反。
%rowcount
该属性用于获取游标的数据行数。
示例:
set serveroutput on
declare
tempsal scott.emp.sal%type;
cursor mycursor is
select * from scott.emp
where sal>tempsal;
cursorrecord mycursor%rowtype;
begin
tempsal:=800;
open mycursor;
if mycursor%isopen then
fetch mycursor into cursorrecord;
dbms_output.put_line(to_char(cursorrecord.deptno));
dbms_output.put_line(to_char(mycursor%rowcount));
else
dbms_output.put_line('游标还未打开');
end if;
end;
相关文档:
1、Session有什么重大BUG,微软提出了什么方法加以解决?
答:是iis中由于有进程回收机制,系统繁忙的话Session会丢失,可以用Sate server或SQL Server数据
库的方式存储Session不过这种方式比较慢,而且无法捕获Session的END事件。
2.产生一个int数组,长度为100,并向其中随机插入1-100,并且不能重复。
C# ......
ALTER procedure [dbo].[sp_lock_check]
@spid1 int = NULL,
@spid2 int = NULL
as
set nocount on
if @spid1 is not NULL
begin
select ......
Select * from t_user_profile where convert ( varchar ( 21 ),regDate, 120 ) like ' 2008-05-07% ' 表名称:t_user_profile 日期字段名称:regDate
Select * from t_user_profile where convert(varchar(21),regDate,120) like '2008-05-07%'< ......
1.条件控制
1.1 if .. then .. end if
if 条件 then
语句段;
end if;
1.2 if .. then .. else .. end if
if 条件 then
语句段;
else
语句段;
end if;
1.3 if嵌套
2.循环控制
2.1 loop .. exit .. end loop
loop
& ......
事务是Oracle9i中进行数据库操作的基本单位,在PL/SQL程序中,可以使用3个事务处理控制命令。
1. commit命令
commit是事务提交命令。Oracle9i数据库中,为保证数据一致性,在内存中为每个客户机建立工作区,客户机对数据库进行操作的事务都在工作区完成,只有执行commit命令后,工作区内的修改内容才写入到数据库上,称 ......