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
- Cursor、Exception、Procedure、Function、Package、Trigger(day06)
回顾: 1.record类型 定义record类型,声明变量,保存s_dept表中id = 31部门信息 declare /* 定义record类型 */ type deptrecord is rec ...
- Delphi 中的 procedure of object
转载:http://www.cnblogs.com/ywangzi/archive/2012/08/28/2659811.html 总结:TMyEvent = procedure of object; ...
- 在PLSQL中编译复杂的java(转)
原文地址:在PLSQL中编译复杂的java PLSQL中可以编译运行JAVA程序. 一个简单的例子: create or replace and compile java source named x ...
- Delphi 中的 procedure of object (类方法存在一个隐藏参数self),简单深刻 good
其实要了解这些东西,适当的学些反汇编,WINDOWS内存管理机制,PE结构,看下李维的VCL架构剖析可以很好理解type TMyEvent = procedure of object;这是一种数据类型 ...
- [独孤九剑]Oracle知识点梳理(六)数据库常用对象之Procedure、function、Sequence
本系列链接导航: [独孤九剑]Oracle知识点梳理(一)表空间.用户 [独孤九剑]Oracle知识点梳理(二)数据库的连接 [独孤九剑]Oracle知识点梳理(三)导入.导出 [独孤九剑]Oracl ...
- --1.plsql中学习job
--1.plsql中学习job --学习job --建表 create table test_job(para_date date); commit; insert into test_job val ...
- plsql中学习job
--1.plsql中学习job --学习job --建表 create table test_job(para_date date); commit; insert into test_job val ...
- 关于PLSQL中的一些问题总结:在PLSQL中书写DDL等
关于问题前导,使用的数据表中涉及到的字段和类型: 在PLSQL中create.drop.truncate等DDL是没有办法直接执行的. 必须要使用: Execute immediate 'DDL语句' ...
- 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 ...
随机推荐
- python用类实现xrange
class xrange(object): def __init__(self, start, end=0, step=1): self.start = start self.end = end se ...
- Android 动画 (1) 基础
背景 坑, 最近打算在recyclerview item上加一个带动画的button,结果button无法连续点击,还以为是动画是同步的,必须要结束之后才能开始另一个动画,后来去掉recylervie ...
- 用generator改写ajax
function request(url) { // this is where we're hiding the asynchronicity, // away from the main code ...
- php操作数组函数
整理了一份PHP开发中数组操作大全,包含有数组操作的基本函数.数组的分段和填充.数组与栈.数组与列队.回调函数.排序.计算.其他的数组函数等. 一.数组操作的基本函数 数组的键名和值 array_va ...
- 读取Excel文件存储在实体类中
1.Maven文件 <!--读取Excel的架包--> <dependency> <groupId>org.apache.poi</groupId> & ...
- MySql解除安全模式:Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.
在修改一条数据字段时报错: Error Code: 1175. You are using safe update mode and you tried to update a table witho ...
- mongodb远程数据库的连接以及备份导入导出数据
环境win10; 运行cmd cd到目录mongodb的bin目录: 连接远程mongodb: 连接命令:mongo -u username -p pwd host:post/database(数据库 ...
- Python基础之面向对象思维解决游戏《天龙八部》
一.程序设计思维: 以面向对象的思维设计<天龙八部>游戏技能,使得技能效果在增加或者减少时,游戏技能整体框架不改变,仅仅增加或者减少技能效果 二.思路流程图如下: 三.变成框架实现代码: ...
- dc的博客翻修计划启动
紫书大部分学习完毕,等待一轮补完计划: 白书正在攻略中,进度百分之30: 博客翻修计划启动,我会在本学期内逐渐写系统性的学习笔记,我学习时遇到的困难的地方会有说明: 每个部分一定会放上经过验证的实现: ...
- [Swift]LeetCode752. 打开转盘锁 | Open the Lock
You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: '0', '1', '2', '3', ...