oralce 存储过程、函数和触发器
用CREATE PROCEDURE命令建立存储过程。
语法:
create [or replace] procedure 过程名(参数列表)
as
PLSQL子程序体;
--给指定员工涨工资
create procedure addSal(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;
--方法一
begin
addSal(7369);
end;
--方法二
exec addSal(7369);
CREATE [OR REPLACE] FUNCTION 函数名 (参数列表)
RETURN 函数值类型
AS
PLSQL子程序体;
--查询指定员工的年收入
create function queryEmpSal(empid in number)
return number
as
psal emp.sal%type;
pcomm emp.comm%type;
begin
select sal,comm into psal,pcomm from emp where empno=empid;
return (psal*12) + nvl(pcomm,0);
end;
declare
psal number;
begin
psal:=queryEmpSal(7369);
dbms_output.put_line(psal);
end;
或
begin
dbms_output.put_line(queryEmpSal(7369));
end;
--包定义
create [or replace] package 包名 as
[公有数据类型定义]
[公有游标声明]
[公有变量、常量声明]
[公有子程序声明]
end 包名; --包主体
create [or replace] package body 包名 as
[私有数据类型定义]
[私有变量、常量声明]
[私有子程序声明和定义]
[公有子程序定义]
begin
PL/SQL子程序体;
end 包名;
--创建mypackage包
create or replace package mypackage as
procedure total(num1 in number, num2 in number, num3 out number);
end mypackage; --mypackage包体
create or replace package body mypackage as
--计算累加和的total过程
procedure total(num1 in number, num2 in number, num3 out number) as
tmp number := num1;
begin
if num2 < num1 then num3 := 0;
else num3 := tmp;
loop
exit when tmp > num2;
tmp := tmp + 1;
num3 := num3 + tmp;
end loop;
end if;
end total; end mypackage;
调用包
declare
num1 number;
begin
mypackage.total(1, 5, num1);
dbms_output.put_line(num1);
end;
oralce 存储过程、函数和触发器的更多相关文章
- MySQL mysqldump 导入/导出 结构&数据&存储过程&函数&事件&触发器
———————————————-库操作———————————————-1.①导出一个库结构 mysqldump -d dbname -u root -p > xxx.sql ②导出多个库结构 m ...
- mysql存储过程、函数和触发器的创建 [转]
http://blog.itpub.net/559237/viewspace-438942/ 今天花了半天时间来研究mysql的存储过程函数和触发器的创建,觉得和oracle的大同小异,只是语法上更艰 ...
- MySQL主从环境下存储过程,函数,触发器,事件的复制情况
下面,主要是验证在MySQL主从复制环境下,存储过程,函数,触发器,事件的复制情况,这些确实会让人混淆. 首先,创建一张测试表 mysql),age int); Query OK, rows affe ...
- MySQL 第十天(视图、存储过程、函数、触发器)
MySql高级-视图.函数.存储过程.触发器 目录 一.视图 1 1.视图的定义 1 2.视图的作用 1 (1)可以简化查询. 1 (2)可以进行权限控制, 3 3.查询 ...
- Mysql 存储过程、函数、触发器和视图的权限检查
当存储过程.函数.触发器和视图创建后,不单单创建者要执行,其它用户也可能需要执行,换句话说,执行者有可能不是创建者本身,那么在执行存储过程时,MySQL是如何做权限检查的? 在默认情况下,MySQL将 ...
- 查看SQL SERVER 加密存储过程,函数,触发器,视图
原文:查看SQL SERVER 加密存储过程,函数,触发器,视图 create PROCEDURE sp_decrypt(@objectname varchar(50))ASbeginset noc ...
- mysql 存储过程,函数,触发器
存储过程和函数 mysql> HELP CREATE PROCEDURE; Name: 'CREATE PROCEDURE' Description: Syntax: CREATE [DEFIN ...
- Mysql学习---视图/触发器/存储过程/函数/执行计划/sql优化 180101
视图 视图: 视图是一个虚拟表(非真实存在),动态获取数据,仅仅能做查询操作 本质:[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用.由 ...
- SQL Server ->> 重新创建Assembly和自动重建相关的数据库编程对象(存储过程,函数和触发器)
在SQL Server中,一旦一个Assembly被其他的数据库编程对象(存储过程,函数和触发器)引用了,这个Assembly就不能被删除.但是问题是,在SQL Server要更新一个Assembly ...
- mysql 视图 触发器 存储过程 函数事务 索引
mysql 视图 触发器 存储过程 函数事务 索引 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当 ...
随机推荐
- sklearn.naive_bayes中几种朴素贝叶斯分类器
区别: 几种朴素贝叶斯分类器的区别在于对于分布的假设,即假设满足的形式. 一.高斯NB 导入 from sklearn.naive_bayes import GaussianNB 假设特征的似然函数满 ...
- ubuntu 命令汇总
1.linux添加全局变量 //查看当前的全局变量 echo $PATH //打开bashrc 文件,在最后面添加需要 加入的目录路径 vi ~/.bashrc //例如: export PATH=$ ...
- MOCK 基本使用例子
package com.icil.esolution.orders; import static org.springframework.test.web.servlet.request.MockMv ...
- spring中 的MD5 加密
//对密码进行加密(不需要使用其他Md5工具 .spring中有 在digestUtils) String password = DigestUtils.md5DigestAsHex( ...
- leetcode476
public class Solution { public int FindComplement(int num) { //计算数字二进制的反码 var list = new List<int ...
- re(正则)模块
import re # re 存在5种使用方式 #1. macth #2.search #3.findall #4.split #5 sub re.match('^chen', 'chenhua123 ...
- Eclipse 工程使用相对路径导入Jar包设置
环境:MyEclipse 6.5 问题:MyEclipse 工程使用相对路径导入Jar包 我们在导入工程时,往往添加Jar都是使用的绝对路径,但这带来了一个问题,不同的用户使用工程都得重新配置Buil ...
- 在eclipse中创建maven项目,亲测有效,详细步骤
一.想要使用maven,首先要配置本地maven的环境 1.在http://maven.apache.org/download.cgi中去下载maven 2. 3.下载完毕后将压缩包解压到自己记住的位 ...
- iOS toll-free bridge
https://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Art ...
- ios 避免navigationcontroller出现时scrollview内容被resize
viewDidLoad中设置以下属性 self.automaticallyAdjustsScrollViewInsets = NO;