procedure:存储过程
eg:
 
create or replace procedure p   --这儿是和plsql的区别
        is
        cursor c
        is 
            select * from emp2 for  update;
        --v_temp c%rowtype;
 
begin
 
        for v_temp in c 
            loop 
                    if(v_temp.sal< 2000) then
                        update emp2 set sal=sal*2 where current of c ;
                    elsif(v_temp.sal = 5000) then
                        delete from emp2  where current of c;
                    end if;
            end loop;
            commit;
end;
 
执行过程的命令:exec p;    begin p end;
 
带参数的存储过程;
create or replace procedure p   --in表示传入参数 out传出参数,
        (v_a in number,v_b number ,v_ret out number,v_temp in out number)
is
 
begin 
        if(v_a > v_b) then
                v_ret := v_a;
        else
            v_ret := v_b;
        end if;
    v_temp := v_temp+1;
end;
 
调用过程:
declare 
        v_a number := 3;
        v_b number := 4;
        v_ret number ;
        v_temp number := 5;
 
begin
            p(v_a,v_b,v_ret,v_temp);
            dbms_output.put_line(v_ret);
            dbms_output.put_line(v_temp);
end;
 
函数:function
 
create or replace  function sal_tax
        (v_sal number)   --声明了一个函数
        return number
is 
begin
        if(v_sal < 2000) then
                return 0.10;
        elsif(v_sal < 2750) then
                return 0.15;
        else
                return 0.20;
        end if;
end;
 
函数的调用::select lower(ename),sal_tax(sal) from emp;
 
触发器:trigger 
不能直接执行,依赖于表
create table emp2_log
(
    uname varchar2(20),
    action varchar2(10),
    atime date
);
 
创建触发器
 
create or replace trigger trig
        after insert or delete or update on emp2 for each row
begin
        if inserting then
            insert into emp2_log values (USER,'insert',sysdate);
        elsif updating then
            insert into emp2_log values(USER,'update',sysdate);
        elsif   deleting then
            insert into emp2_log values (USER,'delete',sysdate);
        end if;
end;
 
update emp2 set sal=sal*2 where deptno = 30;
 
drop triggle trig;(删除)
 
create  or replace trigger    trig
        after update on dept
        for each row 
begin 
        update emp set deptno =:NEW.deptno where deptno = :OLD.deptno;
end;
 
update dept set deptno = 99 where deptno = 10;
 
树状结构的存储于显示:
 
create table ariticle
(
            id number primary key,
            cont varchar2(4000),
            pid number,
            isleaf number(1), -- 0代表非叶子节点,1代表叶子节点
            alevel number(2)
);
 
insert into ariticle values(1,'ahshdhshd',0,0,0);
insert into ariticle values(2,'bhshdhshd',1,0,1);
insert into ariticle values(3,'chshdhshd',2,1,2);
insert into ariticle values(4,dhshdhshd',2,0,2);
insert into ariticle values(5,'ehshdhshd',4,1,3);
insert into ariticle values(6,'fhshdhshd',10,1);
insert into ariticle values(7,'ghshdhshd',6,1,0);
insert into ariticle values(8,'hhshdhshd',3,0,4);

insert into ariticle values(9,'ihshdhshd',7,0,0);
insert into ariticle values(10,'jhshdhshd',9,0,3);
 
commit;(提交)
 
 
 
create or replace procudure p (v_pid ariticle.pid%type,v_level binary_integer)
is cursor c 
    is select * from ariticle where pid = v__pid;
    v_preStr varchar2(1024) :='';
begin 
    for i in 0..v_level loop
        v_preStr :=v_preStr || '       ';
        for v_ariticle in c 
        loop
        dbms_output.put_line(v_preStr || v_ariticle.cont);
           if (v_ariticle.isleaf = 0) then
                p(v_ariticle.id,v_level+1);
            end if;
        end loop;
end;
 
exec p(0);
 
转载至:http://blog.csdn.net/zhaoming262350/article/details/8929878?utm_source=tuicool
转载至:http://blog.csdn.net/zhaoming262350/article/details/8929878?utm_source=tuicool
转载至:http://blog.csdn.net/zhaoming262350/article/details/8929878?utm_source=tuicool

plsql中的procedure和function编程的更多相关文章

  1. Cursor、Exception、Procedure、Function、Package、Trigger(day06)

    回顾: 1.record类型 定义record类型,声明变量,保存s_dept表中id = 31部门信息 declare /* 定义record类型 */ type deptrecord is rec ...

  2. Delphi 中的 procedure of object

    转载:http://www.cnblogs.com/ywangzi/archive/2012/08/28/2659811.html 总结:TMyEvent = procedure of object; ...

  3. 在PLSQL中编译复杂的java(转)

    原文地址:在PLSQL中编译复杂的java PLSQL中可以编译运行JAVA程序. 一个简单的例子: create or replace and compile java source named x ...

  4. Delphi 中的 procedure of object (类方法存在一个隐藏参数self),简单深刻 good

    其实要了解这些东西,适当的学些反汇编,WINDOWS内存管理机制,PE结构,看下李维的VCL架构剖析可以很好理解type TMyEvent = procedure of object;这是一种数据类型 ...

  5. [独孤九剑]Oracle知识点梳理(六)数据库常用对象之Procedure、function、Sequence

    本系列链接导航: [独孤九剑]Oracle知识点梳理(一)表空间.用户 [独孤九剑]Oracle知识点梳理(二)数据库的连接 [独孤九剑]Oracle知识点梳理(三)导入.导出 [独孤九剑]Oracl ...

  6. --1.plsql中学习job

    --1.plsql中学习job --学习job --建表 create table test_job(para_date date); commit; insert into test_job val ...

  7. plsql中学习job

    --1.plsql中学习job --学习job --建表 create table test_job(para_date date); commit; insert into test_job val ...

  8. 关于PLSQL中的一些问题总结:在PLSQL中书写DDL等

    关于问题前导,使用的数据表中涉及到的字段和类型: 在PLSQL中create.drop.truncate等DDL是没有办法直接执行的. 必须要使用: Execute immediate 'DDL语句' ...

  9. Difference between Stored Procedure and Function in SQL Server

    Stored Procedures are pre-compile objects which are compiled for first time and its compiled format ...

随机推荐

  1. Python列表,字典和字符串操作

    列表: 列表:list, 也叫数组,表现[].特点:有角标,元素可以重复,有序的元素 例子:stus = ['王志华','乔美玲','乔美玲','王文文','feixiang']#中括号,这就是一个l ...

  2. Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to ;XX.XX.XX.XX:6379] with root cause

    java.net.ConnectException: Connection refused: no further information at sun.nio.ch.SocketChannelImp ...

  3. AES加密算法详解

    AES 是一个对称密码分组算法,分组长度为128bit,密钥长度为128.192 和 256 bit. 整个加密过程如下图所示. 1.密钥生成算法 密钥扩展过程: 1)  将种子密钥按下图所示的格式排 ...

  4. 201771010126 王燕《面向对象程序设计(Java)》第十四周学习总结(测试程序11)

    实验十四  Swing图形界面组件 理论部分: 不使用布局管理器 有时候可能不想使用任何布局管理器,而只 是想把组件放在一个固定的位置上.下面是将一 个组件定位到某个绝对定位的步骤: 1)将布局管理器 ...

  5. 20175324 2018-2019-2 《Java程序设计》第8周学习总结

    本周学习<Java程序设计>第十五章: 泛型: 泛型(Generics)的主要目的是可以建立具有类型安全的集合框架,如链表.散列映射等数据结构. 泛型类声明:class 名称<泛型列 ...

  6. [LeetCode] Length of Longest Fibonacci Subsequence 最长的斐波那契序列长度

    A sequence X_1, X_2, ..., X_n is fibonacci-like if: n >= 3 X_i + X_{i+1} = X_{i+2} for all i + 2 ...

  7. [LeetCode] Peak Index in a Mountain Array 山形数组的顶峰坐标

    Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists som ...

  8. python从入门到实践-9章类

    #!/user/bin/env python# -*- coding:utf-8 -*- # 类名采用的是驼峰命名法,即将类名中每个单词的首字母大写,而不使用下划线.# 对于每个类,都应紧跟在类定义后 ...

  9. window server 2008 安装Oracle10g

    oracle安装都大同小异. 开始安装步骤 输入完之后点击下一步 这时候稍等一会儿. 这时候也要稍等一会儿. 直接安装. 设置口令管理,设置SCOTT的密码为tiger就好了. 这时候稍等一会儿. o ...

  10. java 的基本数据类型及转换

    数据类型精度: byte 8 位short 16 位int 32 位long 64 位float 32 位double 64 位char 16 位 boolean 占几位要看 jvm 的具体实现, 虽 ...