易截截图软件、单文件、免安装、纯绿色、仅160KB

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;


相关文档:

SQL语句查询是否为空 =null及null

  a                  b                             c&nb ......

Sql Server查看所有数据库名,表名,字段名SQL

1.获取所有数据库名:
SELECT Name from Master..SysDatabases ORDER BY Name
2.获取所有表名:
SELECT Name from DatabaseName..SysObjects Where XType='U' ORDER BY Name
XType='U':表示所有用户表;
XType='S':表示所有系统表;
3.获取所有字段名:
SELECT Name from SysColumns WHERE id=Object_Id('TableNam ......

sql server访问远程数据库

--创建链接服务器
exec sp_addlinkedserver   'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 '
exec sp_addlinkedsrvlogin 'ITSV ', 'false ',null, '用户名 ', '密码 '
--查询示例
select * from ITSV.数据库名.dbo.表名
--导入示例
select * into 表 from ITSV.数据库名.dbo.表名
--以后不 ......

PL/SQL学习笔记三


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  
   & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号