易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

Oracle查询中rownum与Order by查询的关系转

在开发应用的时候,把数据按照一定的规则排序后再取前几条数据这种操作是很平常的事情。我们在Oracle中常用的就是order by,然后取得rownum小于多少的数据这种方法。不过如果对Oracle不熟悉,也许就会发现你写的SQL语句检索出来的值不正确,这个是为什么呢。 因为Oracle在检索的时候,会首先把数据都检索出来,然后在排序段 ......

Oracle 10.1 Statistics

Oracle 10.1 Statistics:
In Oracle 9.2 there were 264 statistics; in Oracle 10.1 there are 332 statistics
The following table shows the 106 statistics that were added in Oracle 10.1:
 
Name
application wait time
cluster wait time
concurrency wait time
consistent gets direct
consistent ......

oracle中重命名列名和表名

我们在创建表结构的过程中,可能会由于失误,造成表中列名错误,如何更改呢,你可能会回答,使用OEM或者PL/SQL,除了这两种方法,我们可以使用命令:
   ALTER TABLE 表名 rename   column  列名 to 新列名     注意column是关键字   /*重命名列名*/
  ALTE ......

区别oracle的单引号和双引号

      对于我们刚入门的oracle初学者来说,学习sql语言是入门的第一步,面对单引号和双引号,我们可能会困惑,什么时候用单引号,什么时候用双引号呢?
    单引号------  值为字符和日期的时候 如  'you'  '06-june'   还有使用连接符||,插入空格||' ......

Oracle更新多行

更新多行的步骤:
步骤多,但效率比较高:
1、create table 临时表 value (select a.id,a.name,b.name,... from table1 a,table2 b where a.id=b.id)
2、删除table1中的记录,不要drop
3、insert into table1 select 你需要的字段 from 临时表。
select * from tb_ai03
create table tb_ai031 as select * from tb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号