oracle存储过程学习(-)-基本过程
2014-04-03 11:58
369 查看
1.存储过程语法
create or replace procedure 存储过程名
is
begin
null;
end;
2.新建一个存储过程
3.如果查询多条数据,用游标,把上面的改进
4.带参数的查询
5.调用上面带参数存储过程
create or replace procedure 存储过程名
is
begin
null;
end;
2.新建一个存储过程
create or replace procedure SELECT_PACT_TYPE is --定义变量 pactTypeId number; typeName nvarchar2(100); begin select t.pact_type_id,t.pact_type_name into pactTypeId, typeName from crm_pact_type t where t.pact_type_id=2;--select into 赋值给变量 from dbms_output.put_line(pactTypeId || typeName);--调试输出 exception when no_data_found then null;--未查到数据 WHEN OTHERS THEN RAISE; end ;
3.如果查询多条数据,用游标,把上面的改进
create or replace procedure SELECT_PACT_TYPE is --定义变量 pactTypeId number; typeName nvarchar2(100); --游标 cursor c is select t.pact_type_id,t.pact_type_name from crm_pact_type t ; begin --循环游标 for cr in c loop begin --赋值 pactTypeId := cr.pact_type_id; typeName := cr.pact_type_name; dbms_output.put_line( pactTypeId || typeName ); end; end loop; exception when no_data_found then null; end ;
4.带参数的查询
create or replace procedure SELECT_PACT_TYPE(id in number) is --定义变量 pactTypeId number; typeName nvarchar2(100); --游标 cursor c is select t.pact_type_id,t.pact_type_name from crm_pact_type t where t.pact_type_id=id; begin --循环游标 for cr in c loop begin --赋值 pactTypeId := cr.pact_type_id; typeName := cr.pact_type_name; dbms_output.put_line( pactTypeId || typeName ); end; end loop; exception when no_data_found then null; end ;
5.调用上面带参数存储过程
declare i number; begin i:=2; -- 调用 id=>i id是存储过程的形参 ,i 是实际参数的值 ,将i的值赋给了id select_pact_type(id => i); end;
相关文章推荐
- MYSQL入门学习之十二:存储过程的基本操作
- 深度学习笔记之关于基本思想、浅层学习、Neural Network和训练过程(三)
- 学习J2SE过程中的30个基本概念
- 我的java/Spring框架入门学习过程(2):IOC的基本操作
- A:学习PHP框架的基本过程
- 黑马程序员之存储过程学习笔记:存储过程的基本使用
- 学习J2SE过程中的30个基本概念
- 学习J2SE过程中的30个基本概念[转]
- C/C++学习日志之一—面向对象和面向过程的基本理解
- MySQL存储过程中的基本函数和触发器的相关学习教程
- LINUX下QT+MYSQL学习笔记-基本入门过程
- 基于不确定性主动学习的基本过程
- oracle存储过程学习(二)-调用存储过程和返回结果集
- ASP.NET MVC5学习笔记之Action参数模型绑定基本过程
- oracle 最简单的学习笔记,增删改查,PLSQL基本语法,游标,函数,存储过程的实现
- 学习J2SE过程中的30个基本概念
- oracle存储过程学习笔记1–基本结构
- 我的java/Springl框架入门学习过程(1):Spring的基本介绍
- 机器学习基本过程