oracle 笔记 III 之存储过程与函数
DML(Manipulation):数据操作语言
CRUD
DDL(Definition): 数据定义语言,与表,索引,同义词有关
create,alter,drop,rename,truncate(清空)
DCL(Control): 数据控制语言,与权限有关
grant,revoke
TCL(Transaction Control): 事务控制语言,与事务有关
commit,rollback,savepoint
==========================
存储过程和存储函数,相当重要,在java需要调用存储过程和函数
写一个例子:写一个函数完成如下功能,输入两个department_id,dept_1,dept_2,返回他们平均工资较高的那个部门中 manager 的salary
函数版:
create or replace function get_mgr(
dept_id_1 employess.department_id%type,
dept_id_2 employees.department_id%type,
)
return number
is
max_sal_1 employees.salary%type;
max_sal_2 employees.salary%type;
dept_id employees.department_id%type;
mgr_id employees.manager_id%type;
sal employees.salary%type;
begin
select max(salary) into max_sal_1 from employees
where department_id = dept_id_1;
select max(salary) into max_sal_2 from employees
where department_id = dept_id_2;
if max_sal_1 > max_sal_2 then
dept_id := dept_id_1;
else
dept_id := dept_id_2;
end if;
select manager_id into mgr_id from departments where department_id = dept_id;
select salary into sal from employees where employee_id = mgr_id;
return sal;
end;
sql版:
第一步 查询给定的两个部门中高的平均工资:30,80
select max(avg_sal)
from (select avg(salary) avg_sal from emplo
相关文档:
Case具有两种格式。简单Case函数和Case搜索函数。
--简单Case函数
CASE sex
WHEN '1' THEN '男'
WHEN '2' THEN '女'
ELSE '其他' END
--Case搜索函数
CASE WHEN sex = '1' THEN '男'
WHEN sex = '2' THEN '女'
ELSE '其他' END
这两种方式,可以实现相同的功能。简单Case函数的写法相对比较简洁 ......
按照OracleDocument中的描述,v$sysstat存储自数据库实例运行那刻起就开始累计全实例(instance-wide)的资源使用情况。
类似于v$sesstat,该视图存储下列的统计信息:
1>.事件发生次数的统计(如:user commits)
2>.数据产生,存取或者操作的total列(如:redo size)
3>.如果TIMED_STATISTICS值为true,则统计花费 ......
以上为转载,多数并未验证.
其中,select trunc(sysdate,'dd') from dual,得到的是: 2009-3-23 上午12:00:00 ,与下文并不一样!
oracle trunc()函数的用法
1.TRUNC(for dates)
TRUNC函数为指定元素而截去的日期值。
其具体的语法格式如下:
TRUNC(date[,fmt])
其中:
date 一个日期值
fmt 日期格式,该日期将 ......
数据字典dict总是属于Oracle用户sys的。
1、用户:
select username from dba_users;
改口令
alter user spgroup identified by spgtest;
2、表空间:
select * from dba_data_files;
select * from dba_tablespaces;//表空间
select tablespace_name,sum(bytes), sum(b ......
Oracle 分析函数使用介绍
分析函数是oracle816引入的一个全新的概念,为我们分析数据提供了一种简单高效的处理方式.在分析函数出现以前,我们必须使用自联查询,子查询或者内联视图,甚至复杂的存储过程实现的语句,现在只要一条简单的sql语句就可以实现了,而且在执行效率方面也有相当大的提高.下面我将针对分析函 ......