码迷,mamicode.com
首页 > 数据库 > 详细

Oracle_071_lesson_p17

时间:2018-08-10 17:14:29      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:ural   using   ror   sso   eve   delete   join   ora   value   

Manipulating Data by Using Subqueries 使用子查询控制数据

you should be able to:
1、Use subqueries to manipulate data
2、Insert values by using a subquery as a target
3、Use the WITH CHECK OPTION keyword on DML statements
4、Use correlated subqueries to update and delete rows

You can use subqueries in data manipulation language (DML) statements to:
1、Retrieve data by using an inline view
2、Copy data from one table to another
3、Update data in one table based on the values of another table
4、Delete rows from one table based on rows in another table

INSERT INTO (SELECT l.location_id, l.city, l.country_id
FROM loc l
JOIN countries c
ON(l.country_id = c.country_id)
JOIN regions USING(region_id)
WHERE region_name = ‘Europe‘)
VALUES (3300, ‘Cardiff‘, ‘UK‘);

SELECT location_id, city, country_id
FROM loc;

Using the WITH CHECK OPTION Keyword on DML Statements

INSERT INTO ( SELECT location_id, city, country_id
FROM loc
WHERE country_id IN
(SELECT country_id
FROM countries
NATURAL JOIN regions
WHERE region_name = ‘Europe‘)
WITH CHECK OPTION )
VALUES (3600, ‘Washington‘, ‘US‘);
Error report:
SQL Error: ORA-01402: view WITH CHECK OPTION where-clause violation

  1. 00000 - "view WITH CHECK OPTION where-clause violation"
    Cause:
    Action:

Correlated UPDATE
UPDATE table1 alias1
SET column = (SELECT expression
FROM table2 alias2
WHERE alias1.column =
alias2.column);

ALTER TABLE empl6
ADD(department_name VARCHAR2(25));

UPDATE empl6 e
SET department_name =
(SELECT department_name
FROM departments d
WHERE e.department_id = d.department_id);

Correlated DELETE
DELETE FROM table1 alias1
WHERE column operator
(SELECT expression
FROM table2 alias2
WHERE alias1.column = alias2.column);

DELETE FROM empl6 E
WHERE employee_id =
(SELECT employee_id
FROM emp_history
WHERE employee_id = E.employee_id);

Oracle_071_lesson_p17

标签:ural   using   ror   sso   eve   delete   join   ora   value   

原文地址:http://blog.51cto.com/3938853/2157306

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!