易截截图软件、单文件、免安装、纯绿色、仅160KB

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 =


相关文档:

ORACLE PL/SQL 集合学习笔记(三)

四、联合数组的使用方法
联合数组以前被称为PL/SQL表。在表中不能使用联合数组,只能将它们用作程序设计的结构体。只能在PL/SQL中访问联合数组。
注意到联合数组带来的一些关键问题是非常重要的。这些问题使我们介绍它们的用法时,需要采取一些特别的方法。这些问题包括:
联合数组不需要初始化,也没有构造函数语法。在 ......

Oracle动态性能表

(1) v$sql
  一条语句可以映射多个cursor,因为对象所指的cursor可以有不同用户(如例1)。如果有多个cursor(子游标)存在,在V$SQLAREA为所有cursor提供集合信息。
例1:
这里介绍以下child cursor
user A: select * from tbl
user B: select * from tbl
大家认为这两条语句是不是一样的啊,可能会有很多人会说是一样 ......

ORACLE PL/SQL开发

刚刚在inthirties老大的博客里看到这篇文章,写的不错,正好自己最近在学习PL/SQL,转过来学习学习。
==================================================================================
bulk collect是可以看做是一种批获取的方式,在我们的plsql的代码段里经常作为into的扩展来使用。对于select id into v from ... ......

ORACLE CASE函数

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函数的写法相对比较简洁 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号