oracle 笔记 II 之DML:数据操作语言
DML:Data Manipulation Language 数据操作语言
包括:CRUD
1. insert语句
(1) 从其它表中复制数据,实现方法:在insert 语句中加入查询语句
insert into sales_reps(id,name,salary,commission_pct) select employee_id,last_name,salary,commission_pct
from employees where job_id like '%rep';
(2) update中使用子查询
update employees set job_id = (select job_id from employees where employee_id = 205),
salary = (select salary from employees where employee_id = 205)
where employee_id = 114;
如:更新114号员工的工作和工资使其与205号员工相同
update employees set job_id = (select job_id from employees where employee_id = 205),
salary = (select salary from employees where employee_id = 205)
where employee_id = 114
再看一个问题,仔细体会解决步骤:
更改 108 员工的信息: 使其 工资变为所在部门中的最高工资,job变为公司中平均工资最低的job
分析:
第1 步 首先查询 108 所在部门的最高工资是多少
select max(salary) from employees where department_id =
( select department_id from employees where employee_id = 108)
第 2 步 查询公司中平均工资最低的 job_id
select job_id from employees group by job_id having avg(salary) =
(select min(avg_sal) from(select avg(salary) avg_sal from employees group by job_id) )
第 3 步 实现更新
update employees set salary = ( select max(salary) from employees
where department_id =
相关文档:
二、以形参的形式定义和使用记录、对象类型
在用作形式参数时,记录类型和对象类型有很多相同之处。在将它们作为游标、函数或过程的形式参数以前,事先都必须定义一个记录类型或者对象类型。
如下例所示:
记录
DECLARE
-- Define a record type.
TYPE individual_record IS RECORD
(individual_id ......
三、嵌套表的使用方法
1、将嵌套表定义为PL/SQL的程序构造块
TYPE type_name IS TABLE OF element_type[NOT NULL];
如下例所示:
DECLARE
-- Define a nested table of variable length strings.
TYPE card_table IS TABLE OF VARCHAR2(5 CHAR);
-- Declare and initialize a n ......
导读:
2009年9月Oracle公司发布了期待已久的Oracle 11g R2,本系列文章将给读者一一揭开新版本中的新特性,并会介绍企业如何利用这些新特性将现有的Oracle 9i,10g,11g R1升级到Oracle 11g R2.
经历了难以忍受的长时间等待,Oracle公司突然在9月1发布了Oracle 11g R2,我不得不承认Oracle的保密工作做得 ......
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,则统计花费 ......