Basic Update Statements
Update all records UPDATE
SET
CREATE TABLE test AS
SELECT object_name, object_type
FROM all_objs;
SELECT DISTINCT object_name
FROM test;
UPDATE test
SET object_name = 'OOPS';
SELECT DISTINCT object_name
FROM test;
ROLLBACK;
Update a specific record UPDATE
SET
WHERE
SELECT DISTINCT object_name
FROM test;
UPDATE test
SET object_name = 'LOAD'
WHERE object_name = 'DUAL';
COMMIT;
SELECT DISTINCT object_name
FROM test
Update based on a single queried value
UPDATE
SET
SELECT
FROM
CREATE TABLE test AS
SELECT table_name
FROM all_tables;
ALTER TABLE test
ADD (lower_name VARCHAR2(30));
SELECT *
FROM test
WHERE table_name LIKE '%A%';
UPDATE test t
SET lower_name = (
SELECT DISTINCT lower(table_name)
FROM all_tables a
WHERE a.table_name = t.table_name
AND a.table_name LIKE '%A%');
COMMIT;
SELECT *
FROM test;
Update based on a query returning multiple values UPDATE
SET (
SELECT (
FROM
WHERE
CREATE TABLE test AS
SELECT t. table_name, t. tablespace_name, s.extent_management
FROM user_tables t, user_tablespaces s
WHERE t.tablespace_name = s. tablespace_name
AND 1=2;
desc test
SELECT * FROM test;
-- does not work
UPDATE test
SET (table_name, tablespace_name) = (
SELECT table_name, tablespace_name
FROM user_tables);
-- works
INSERT INTO test
(table_name, tablespace_name)
SELECT table_name, tablespace_name
FROM user_tables;
COMMIT;
SELECT *
FROM test
WHERE table_name LIKE '%A%';
-- does not work
UPDATE test t
SET tablespace_name, extent_management = (
SELECT tablespace_name, extent_management
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name
AND t.table_name LIKE '%A%');
-- does not work
UPDATE test t
SET (tablespace_name, extent_management) = (
SELECT DISTINCT u.tablespace_name, u.extent_management
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name
AND t.table_name LIKE '%A%');
rollback;
-- works
UPDATE test t
SET (tablespace_name, extent_management) = (
SELECT DISTINCT u.tablespace_name, u.extent_management
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name)
WHERE t.table_name LIKE '%A%';
COMMIT;
SELECT *
FROM test;
Update the results of a SELECT statement UPDATE ()
SET
SELECT
FROM
WHERE
conn hr/hr
CREATE TABLE empbak AS
SELECT * FROM employees;
UPDATE employees
SET salary = salary * 1.1;
COMMIT;
UPDATE employees t1
SET salary = (
SELECT salary
FROM empbak t2
WHERE t1.employee_id = t2.employee_id);
Multi-column UPDATE TABLE()
SET ....;
conn hr/hr
var bnd1 NUMBER
var bnd2 VARCHAR2(30)
var bnd3 NUMBER
UPDATE employees
SET job_id ='SA_MAN', salary = salary + 1000,
department_id = 140
WHERE last_name = 'Jones'
RETURNING salary*0.25, last_name, department_id
INTO :bnd1, :bnd2, :bnd3;
print bnd1
print bnd2
print bnd3
conn hr/hr
variable bnd1 NUMBER
UPDATE employees
SET salary = salary * 1.1
WHERE department_id = 100
RETURNING SUM(salary) INTO :bnd1;
print bnd1
Update Object Table
Update a table object UPDATE (
'Drop Database' 카테고리의 다른 글
Oracle10g에서 CONNECT BY (0) | 2007.10.29 |
---|---|
오라클 변환형 함수 (0) | 2007.10.24 |
Sequence 이용 (0) | 2007.10.18 |
LOB DATA TYPE의 이해 (0) | 2007.10.17 |
오라클 함수 정리...아..지겨워..맨날 정리..정리.. (0) | 2007.10.17 |