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
相关文档:
oracle表空间操作详解
1
2
3作者: 来源: 更新日期:2006-01-04
5
6
7建立表空间
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
数据字典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(blocks)
from dba_ ......
Oracle 分析函数使用介绍
分析函数是oracle816引入的一个全新的概念,为我们分析数据提供了一种简单高效的处理方式.在分析函数出现以前,我们必须使用自联查询,子查询或者内联视图,甚至复杂的存储过程实现的语句,现在只要一条简单的sql语句就可以实现了,而且在执行效率方面也有相当大的提高.下面我将针对分析函 ......
查询及删除重复记录的SQL语句
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据 ......
序列(SEQUENCE)是序列号生成器,可以为表中的行自动生成序列号,产生一组等间隔的数值(类型为数字)。其主要的用途是生成表的主键值,可以在插入语句中引用,也可以通过查询检查当前值,或使序列增至下一个值。
创建序列需要CREATE SEQUENCE系统权限。序列的创建语法如下:
CREATE SEQUENCE 序列名
[INCREMENT BY n]
[ST ......