Oracle存储过程总结(一、基本应用)
1、创建存储过程
create or replace procedure test(var_name_1 in type,var_name_2 out type) as
--声明变量(变量名 变量类型)
begin
--存储过程的执行体
end test;
打印出输入的时间信息
E.g:
create or replace procedure test(workDate in Date) is
begin
dbms_output.putline('The input date is:'||to_date(workDate,'yyyy-mm-dd'));
end test;
2、变量赋值
变量名 := 值;
E.g:
create or replace procedure test(workDate in Date) is
x number(4,2);
begin
x := 1;
end test;
3、判断语句:
if 比较式 then begin end; end if;
E.g
create or replace procedure test(x in number) is
begin
if x >0 then
begin
x := 0 - x;
end;
end if;
if x = 0 then
begin
x: = 1;
end;
end if;
end test;
4、For 循环
For ... in ... LOOP
--执行语句
end LOOP;
(1)循环遍历游标
create or replace procedure test() as
Cursor cursor is select name from student; name varchar(20);
begin
for name in cursor LOOP
begin
dbms_output.putline(name);
end;
end LOOP;
end test;
(2)循环遍历数组
create or replace procedure test(varArray in myPackage.TestArray) as
--(输入参数varArray 是自定义的数组类型,定义方式见标题6)
i number;
begin
i := 1; --存储过程数组是起始位置是从1开始的,与java、C、C++等语言不同。因为在Oracle中本是没有数组的概念的,数组其实就是一张
--表(Table),每个数组元素就是表中的一个记录,所以遍历数组时就相当于从表中的第一条记录开始遍历
for i in 1..varArray.count LOOP
dbms_output.putline('The No.'|| i || 'record in varArray is:'||varArray(i));
end LOOP;
end test;
5、While 循环
whi
相关文档:
What circumstances we use ALL_ROWS and what circumstances we use FIRST_ROWS optimizer mode? This article is written in oracle9i.
First_rows attempts to optimize the query to get the very first row back to the client as fast as possible. This is good for an interactive client server environment wher ......
在开发应用的时候,把数据按照一定的规则排序后再取前几条数据这种操作是很平常的事情。我们在Oracle中常用的就是order by,然后取得rownum小于多少的数据这种方法。不过如果对Oracle不熟悉,也许就会发现你写的SQL语句检索出来的值不正确,这个是为什么呢。 因为Oracle在检索的时候,会首先把数据都检索出来,然后在排序段 ......
转自:http://hi.baidu.com/dashuaiwang/blog/item/47cc680ec35055c37acbe1f8.html
打开oracle 数据库时出现了错误:
ORA-00313: 无法打开日志组 1 (线程 1) 的成员
ORA-00312: 联机日志 1 线程 1: 'D:\ORACLE\ORADATA\GOCOM\REDO01.LOG'
SQL> connect / as sysdba;
已连接。
SQL> shutdown immediate;
ORA- ......
ORACLE的lpad函数、rpad函数用法
语法:select lpad('12345678',1,'0') from dual;
返回字符串‘12345678’的从左边长度为1的字符串,如果不够,左边补‘0’
语法:select rpad('12345678',1,'0') from dual;
返回字符串‘12345678’的从左边长度为1的字符串,如果不够,右边补&ls ......
Oracle 总帐模块的一个会计业务周期如下:
1.打开总帐会计期
2.录入手工凭证,包括:· 手工标准凭证
  ......