oracle存储过程相关
来源:互联网 发布:linux的arp表大小 编辑:程序博客网 时间:2024/06/15 08:32
1、创建Create or Replace Procedure pName(praram in out type,..) is
示例:
Create Or Replace Procedure pTest(name in varchar2) is
Begin
语句...
End pTest;
2、游标使用Cursor
Create Or Replace Procedure pTest(name in varchar2) is
Cursor cursor1 is select id from pTest where ...;
Begin
语句...
End pTest;
3、遍历Cursor方法
For tempCrs in Cursor1 Loop
tempCrs.id
End Loop;
4、Cursor使用方法2
Create Or Replace Procedure pTest(name in varchar2) is
Cursor cursor1;
Begin
select id into cursor1 from pTest where ..;
other..
End pTest;
5、带参数Cursor使用
Create Or Replace Procedure pTest(name in varchar2) is
Cursor cursor1(t_id number) is select id from pTest where typeid=t_id;
Begin
For tempCrs in cursor1(10) Loop
other..
End pTest;
6、SELECT INTO STATEMENT
将select查询的结果存入到变量中,可以同时将多个列存储多个变量中,必须有一条
记录,否则抛出异常(如果没有记录抛出NO_DATA_FOUND)
例子:
BEGIN
SELECT col1,col2 into 变量1,变量2 FROM typestruct where xxx;
EXCEPTION
WHEN NO_DATA_FOUND THEN
xxxx;
END;
7、基本语句
if 比较式 then
begin
end;
end if;
while i<100 Loop
begin
...
end ;
end Loop;
for x in y loop
begin
..
end ;
end loop;
赋值 :=
create or replace procedure test(varArray in myPackage.TestArray) as
--(输入参数varArray 是自定义的数组类型)
i number;
begin
i := 1;
--存储过程数组是起始位置是从1开始的,与java、C、C++等语言不同。因为在Oracle中本是没有数组的概念的,数组其实就是一张
--表(Table),每个数组元素就是表中的一个记录,所以遍历数组时就相当于从表中的第一条记录开始遍历
For i in varArray.count LOOP
dbms_output.putline('The No.'|| i || 'record in varArray is:'||varArray(i));
end LOOP;
end test;
(2)自定义的数组类型 (自定义数据类型时,建议通过创建Package的方式实现,以便于管理)
create or replace package myPackage is
-- Public type declarations type info is record( name varchar(20), y number);
type TestArray is table of info index by binary_integer;
--此处声明了一个TestArray的类型数据,其实其为一张存储Info数据类型的Table而已,及TestArray 就是一张表,有两个字段,一个是name,一个是y。需要注意的是此处使用了Index by binary_integer 编制该Table的索引项,也可以不写,直接写成:type TestArray is table of info,如果不写的话使用数组时就需要进行初始化:varArray myPackage.TestArray; varArray := new myPackage.TestArray();
end TestArray;
- oracle存储过程相关
- Oracle存储过程总结(二、字符串处理相关函数)
- 详细讲解有关Oracle存储过程的相关问题
- Oracle存储过程总结(二、字符串处理相关函数)
- ORACLE JOB和存储过程的相关查询
- Oracle存储过程总结(二、字符串处理相关函数)
- Oracle存储过程总结(二、字符串处理相关函数)
- Oracle存储过程总结(二、字符串处理相关函数)
- Oracle存储过程总结(二、字符串处理相关函数)
- Oracle存储过程总结(二、字符串处理相关函数)
- Oracle存储过程总结(二、字符串处理相关函数)
- oracle存储过程——按id更新相关信息
- oracle存储过程——插入相关信息
- 详细讲解有关Oracle存储过程的相关问题
- Oracle存储过程总结(二、字符串处理相关函数)
- Oracle存储过程总结(二、字符串处理相关函数)
- Oracle存储过程总结(二、字符串处理相关函数)
- Oracle存储过程总结(二、字符串处理相关函数)
- 实现页面中按钮刷新的N种方法
- Symbian中音频API的使用
- ASP.NET 2.0服务器控件必须放具有runat="server"的窗体标记内
- linphone编译(一) linux 下 无video编译
- blog
- oracle存储过程相关
- IP地址
- _beginthreadex / CreateThread 的用法
- VxWorks基本概念及常见问题
- FTP使用的内部命令
- jQuery1.4源码学习一
- ext 3.0 中文文档下载
- CommandExecutor和Interceptor
- web前端基础