oracle存储过程和触发器
来源:互联网 发布:皓月乒乓 淘宝店铺 编辑:程序博客网 时间:2024/05/17 03:53
Oracle的Scott用户
1、存储过程示例:为指定的职工在原工资的基础上长10%的工资
SQL> create or replace procedure raiseSalary(empid in number)
as
pSal emp.sal%type;
begin
select sal into pSal from emp where empno=empid;
update emp set sal = sal*1.1 where empno=empid;
dbms_output.put_line('员工号:' || empid || '涨工资前
' || psal || '涨工资后' || psal*1.1);
end;
/
Procedure created
SQL> set serveroutput on
SQL> exec raisesalary(7369);
员工号:7369涨工资前
800涨工资后880
PL/SQL procedure successfully completed
2、存储函数示例:查询某职工的年收入。
SQL> /**/
/*
查询某职工的总收入
*/
create or replace function queryEmpSalary(empid in number)
return number
as
pSal number; --定义变量保存员工的工资
pComm number; --定义变量保存员工的奖金
begin
select sal,comm into psal,pcomm from emp where empno = empid;
return psal*12+nvl(pcomm,0);
end;
/
Function created
SQL> declare
v_sal number;
begin
v_sal:=queryEmpSalary(7934);
dbms_output.put_line('salary is:'|| v_sal);
end;
/
salary is:15600
PL/SQL procedure successfully completed
SQL> begin
dbms_output.put_line('salary is:'|| queryEmpSalary(7934));
end;
/
salary is:15600
PL/SQL procedure successfully completed
3、创建触发器示例1:限制非工作时间向数据库插入数据
SQL> create or replace
trigger securityEmp
before insert on emp
declare
begin
if to_char(sysdate,'day')in('星期四','星期六','星期日')
or to_number(to_char(sysdate,'hh24'))not between 8 and 18 then
raise_application_error(-20001,'不能在非工作时间插入数据。');
end if;
end;
/
Trigger created
4、创建触发器示例2:确认数据(检查emp表中sal 的修改值不低于原值)
SQL> create or replace trigger checkSal
before update of sal on emp
for each row
declare
begin
if :new.sal<:old.sal then
raise_application_error(-20001,'更新后的薪水比更新前小');
end if;
end;
/
Trigger created
- oracle存储过程和触发器
- oracle存储过程和触发器
- oracle触发器和存储过程
- oracle触发器和存储过程
- 关于oracle存储过程和触发器
- Oracle中的存储过程,函数和触发器
- Oracle的存储过程、函数和触发器
- oracle 触发器和存储过程简单例子
- oracle中的游标,例外,存储过程,存储函数和触发器
- 触发器和存储过程
- 触发器和存储过程
- 触发器和存储过程
- 触发器和存储过程
- 存储过程和触发器
- 存储过程和触发器
- 存储过程和触发器
- 触发器和存储过程
- 存储过程和触发器
- makefile的语法及写法
- 输出EXCEL报表时如何将科学计数法字段改为文本
- 位运算.
- android 开源组件
- frontend日常
- oracle存储过程和触发器
- HTML5的localStorage本地化存储
- VMware vCloud架构
- 英特尔® 硬件加速执行管理器安装指南 — Mac OS X*
- 安卓 intent.putExtra()方法参数详解
- Retrying connect to server: :9000. Already tried 0 time(s)
- http://blog.csdn.net/chenxijie888/article/details/6876628
- 我们都变得可怕
- JDK环境变量设置详解