存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中。用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。存储过程是数据库中的一个重要对象,任何一个设计良好的数据库应用程序都应该用到存储过程。
1.有输入参数的存储过程
create or replace stu_proc1 procedure (pno in student.son%type) as
pname vchar2(25);
begin
select sname into pname from student where son=pon;
Dbms_output.ut_line(pname);
end;
2.有输出参数的存储过程
create or replace stu_proc1 procedure (pname stutdent.sname%type) as
begin
select sname into pname from student where son=1;
bms_output.ut_line(pname);
end;
3.有输入输出参数的存储过程
create or replace stu_proc1 procedure (pno in student.son%type,pname utdent.sname%type) as
begin
select sname into pname from student where son=pno ;
Dbms_output.ut_line(pname);
end;
4.无参数
create or replace stu_proc1 procedure as
pname vchar2(25);
begin
select sname into pname from student where son=1;
bms_output.ut_line(pname);
end;
存储过程创建语法:
create or replace procedure 存储过程名(param1 in type,param2 out type)
as
变量1 类型(值范围);
变量2 类型(值范围);
Begin
Select count(*) into 变量1 from 表A where列名=param1;
If (判断条件) then
Select 列名 into 变量2 from 表A where列名=param1;
Dbms_output。Put_line(‘打印信息’);
Elsif (判断条件) then
Dbms_output。Put_line(‘打印信息’);
Else
Raise 异常名(NO_DATA_FOUND);
End if;
Exception
When others then
Rollback;
End;
注意事项:
1, 存储过程参数不带取值范围,in表示传入,out表示输出
2, 变量带取值范围,后面接分号
3, 在判断语句前最好先用count(*)函数判断是否存在该条操作记录
4, 用select 。。。into。。。给变量赋值
5, 在代码中抛异常用 raise+异常名
以命名的异常
命名的系统异常 产生原因
ACCESS_INTO_NULL 未定义对象
CASE_NOT_FOUND CASE 中若未包含相应的 WHEN ,并且没有设置
ELSE 时
COLLECTION_IS_NULL 集合元素未初始化
CURSER_ALREADY_OPEN 游标已经打开
DUP_VAL_ON_INDEX 唯一索引对应的列上有重复的值
INVALID_CURSOR 在不合法的游标上进行操作
INVALID_NUMBER 内嵌的 SQL 语句不能将字符转换为数字
NO_DATA_FOUND 使用 select into 未返回行,或应用索引表未初始化的
TOO_MANY_ROWS 执行 select into 时,结果集超过一行
ZERO_DIVIDE 除数为 0
SUBSCRIPT_BEYOND_COUNT 元素下标超过嵌套表或 VARRAY 的最大值
SUBSCRIPT_OUTSIDE_LIMIT 使用嵌套表或 VARRAY 时,将下标指定为负数
VALUE_ERROR 赋值时,变量长度不足以容纳实际数据
LOGIN_DENIED PL/SQL 应用程序连接到 oracle 数据库时,提供了不
正确的用户名或密码
NOT_LOGGED_ON PL/SQL 应用程序在没有连接 oralce 数据库的情况下
访问数据
PROGRAM_ERROR PL/SQL 内部问题,可能需要重装数据字典& pl./SQL
系统包
ROWTYPE_MISMATCH 宿主游标变量与 PL/SQL 游标变量的返回类型不兼容
SELF_IS_NULL 使用对象类型时,在 null 对象上调用对象方法
STORAGE_ERROR 运行 PL/SQL 时,超出内存空间
SYS_INVALID_ID 无效的 ROWID 字符串
分享到:
相关推荐
存储过程(Stored Procedure)是一组为了完 成特定功能的 SQL 语句集,经编译后存储在数据库中。用户通过指定存储过程的名字并给 出参数(如果该存储过程带有参数)来执行它。存储过程是数据库中的一个重要对象,...
学习使用存储过程(Stored Procedure),是ASP程序员的必须课之一。所有的大型数据库SPAN>都支持存储过程,比如Oracle、MS SQL等,(但MS Access不支持,不过,在Access里可以使用参数化的查询)
Using Informatica Stored Procedure Transformation
mysql存储过程方面的圣经,以通俗的示例方法讲述mysql存储过程的深奥内容,In MySQL Stored Procedure Programming, they put that hard-won experience to good use. Packed with code examples and covering ...
存储过程(Stored Procedure), 是一组为了完成特定功能的SQL 语句,集经编译后 存储在数据库中,用户通过指定存储过程的名字并给出参数,如果该存储过程带有参数来执行它, 在SQL Server 的系列版本中,存储过程...
存储过程 Stored Procedure4.1. 存储过程概述4.1.1. 存储过程的优点4.1.2. 存储过程的缺点4.2. 创建存储过程 create procedure4.2.1. 参数 in、out、inout4.3. 调用存储过程 call4.4. 查看存储过程4.4.1. 查看存储...
MySQL Stored Procedure Programming Advance Praise for MySQL Stored Procedure Programming Preface Objectives of This Book Structure of This Book What This Book Does Not Cover Conventions ...
简单明了的教程,快速入门,强烈推荐。也是735认证考试的材料。
sybase stored procedure
mysql stored procedure programming PDF version
The implementation of stored procedures in MySQL 5.0 ... This book, destined to be the bible of stored procedure development, is a resource that no real MySQL programmer can afford to do without.
SQL Server 2000 Stored Procedure Programming SQL SERVER 2000存储过程编程,英文版,pdf文件,6M左右,贼清晰
TERADATA SQL Reference:UDF, UDM, and External Stored Procedure Programming
一个基于ADO.NET+COBOL+Stored Procedure的程序例子代码。
资源名称:SQL_Server存储过程调试指南内容简介: 存储过程( Stored Procedure)是一组为了完成特定功能的 SQL 语句集,经编译后存储在数据库中。用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来...
一个基于C#实现的后台运行 any stored procedure 的类库源码程序
存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户 通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。而我们常用的操作...
SQL语句需要先编译然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给定参数(如果该存储过程带有参数)来调用执行它。...
解决OracleRAC集群下创建SDE时报Stored procedures错误问题 环境:Oracle11.2.0.3 两节点RAC集群,windows server2008R2,FCSAN共享存储,ArcGIS Desktop 1031
A tool to generate class files to implement stored procedures创建类文件执行存储过程的工具