PL/SQL学习笔记六
1.创建过程
create or replace procedure 过程名 as
声明语句段;
begin
执行语句段;
exception
异常处理语句段;
end;
2. 带参数的过程
参数类型3种
in参数:读入参数,主程序向过程传递参数值
out参数:输出参数,过程向主程序传递参数值
in out参数:双向参数
定义带参数的过程示例:
Set serveroutput on
create or replace procedure scott.tempprocedure(
tempdeptno in scott.dept.deptno%type, --输入参数
tempdname out scott.dept.dname%type, --输出参数
temploc in out scott.dept.loc%type) as -- 双向参数
loc1 scott.dept.loc%type;
dname1 scott.dept.dname%type;
begin
select loc into loc1
from scott.dept
where deptno=tempdeptno;
select dname into dname1
from scott.dept
where deptno=tempdeptno;
temploc:='地址:'||loc1;
tempdname:='姓名'||dname1;
end;
使用带参数的过程示例:
set serveroutput on
declare
myno scott.dept.deptno%type;
mydname scott.dept.dname%type;
myloc scott.dept.loc%type;
begin
myno:=10;
mydname:='';
myloc:='';
scott.tempprocedure(myno,mydname,myloc);
dbms_output.put_line(myno);
dbms_output.put_line(mydname);
dbms_output.put_line(myloc);
end;
相关文档:
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 ......
select Convert( varchar(20) , 时间字段 , 格式 ) from 表 如:select Convert(varchar(20),LOGIN_DATE,112) from dbo.C_PARTY_CLIENT 100:Jun 22 2009 12:00AM 101:06/22/2009 102:2009.06.22 103:22/06/2009 104:22.06.2009 105:22-06-2009 106:22
select Convert(varchar(20),<时间字段>,<格式>) f ......
ALTER procedure [dbo].[sp_lock_check]
@spid1 int = NULL,
@spid2 int = NULL
as
set nocount on
if @spid1 is not NULL
begin
select ......
sql server 时间段查询。
==========================================
select g.borrowTime from t_apartment_goodsborrow g
where g.borrowTime >= '2010-03-11 9:50:43'
2010-03-11 9:52:54
----------------------------------------------------------------------------
select g.borrowTime ......
游标是从数据库中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向首记录, 利用fetch语句移动该指针,从而对游标中的数据进行各种操作。
1.定义游标
cursor 游标名 is select语句;
2.打开游标
open 游标名;
3.提取游标数据
fetch 游标名 into 变量名1, 变量名2, ....;
或
......