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 =
相关文档:
在PL/SQL程序设计中,有三种定义记录类型的方法:一种是使用%ROWTYPE属性;另一种是在PL/SQL程序的声明部分显示定义记录类型;最后一种方法是将记录类型定义为数据库结构或对象类型。
我先简单的介绍一个下面要用到的表的结构(黑体标明的字段为主键):
INDIVIDUALS表
INDIVIDUAL ID
FIRST NAME
MIDDLE_INITI ......
二、以形参的形式定义和使用记录、对象类型
在用作形式参数时,记录类型和对象类型有很多相同之处。在将它们作为游标、函数或过程的形式参数以前,事先都必须定义一个记录类型或者对象类型。
如下例所示:
记录
DECLARE
-- Define a record type.
TYPE individual_record IS RECORD
(individual_id ......
导读:
2009年9月Oracle公司发布了期待已久的Oracle 11g R2,本系列文章将给读者一一揭开新版本中的新特性,并会介绍企业如何利用这些新特性将现有的Oracle 9i,10g,11g R1升级到Oracle 11g R2.
经历了难以忍受的长时间等待,Oracle公司突然在9月1发布了Oracle 11g R2,我不得不承认Oracle的保密工作做得 ......
刚刚在inthirties老大的博客里看到这篇文章,写的不错,正好自己最近在学习PL/SQL,转过来学习学习。
==================================================================================
bulk collect是可以看做是一种批获取的方式,在我们的plsql的代码段里经常作为into的扩展来使用。对于select id into v from ... ......
本视图包括Shared pool中SQL语句的完整文本,一条SQL语句可能分成多个块被保存于多个记录内。
V$SQLTEXT中的常用列
HASH_VALUE:SQL语句的Hash值
ADDRESS:sql语句在SGA中的地址
SQL_TEXT:SQL文本。
PIECE:SQL语句块的序号
V$SQLTEXT中的连接列
Column View   ......