E Computer Notes - Oracle9i Extensions To DML and DDL Statements
E Computer Notes - Oracle9i Extensions To DML and DDL Statements
Objectives
After completing this lesson, you should be able to do the following:
Describe the features of multitable inserts Use the following types of multitable inserts
Unconditional INSERT Pivoting INSERT Conditional ALL INSERT Conditional FIRST INSERT
Create and use external tables Name the index at the time of creating a primary
key constraint
.
INSERT INTO departments(department_id, department_name, manager_id, location_id) VALUES (70, 'Public Relations', 100, 1700); 1 row created.
SET [WHERE
[,
Update more than one row at a time, if required. Specific row or rows are modified if you specify the WHERE clause.
1 row updated.
The INSERT...SELECT statement can be used to insert rows into multiple tables as part of a single DML statement. Multitable INSERT statements can be used in data warehousing systems to transfer data from one or more operational sources to a set of target tables. improvement over:
conditional_insert_clause
[ALL] [FIRST] [WHEN condition THEN] [insert_into_clause values_clause] [ELSE] [insert_into_clause values_clause]
http://ecomputernotes.com
http://ecomputernotes.com
.
http://ecomputernotes.com
.
http://ecomputernotes.com
Pivoting INSERT
Suppose you receive a set of sales records from a nonrelational database table, SALES_SOURCE_DATA in the following format: EMPLOYEE_ID, WEEK_ID, SALES_MON, SALES_TUE, SALES_WED, SALES_THUR, SALES_FRI
Pivoting INSERT
INSERT ALL INTO sales_info VALUES (employee_id,week_id,sales_MON)
INTO sales_info VALUES (employee_id,week_id,sales_TUE) INTO sales_info VALUES (employee_id,week_id,sales_WED)
SELECT EMPLOYEE_ID, week_id, sales_MON, sales_TUE, sales_WED, sales_THUR,sales_FRI FROM sales_source_data; 5 rows created.
http://ecomputernotes.com
External Tables
External tables are read-only tables in which the data is stored outside the database in flat files. The metadata for an external table is created using a CREATE TABLE statement. With the help of external tables, Oracle data can be stored or unloaded as flat files. The data can be queried using SQL, but you cannot use DML and no indexes can be created.
http://ecomputernotes.com
Create a DIRECTORY object that corresponds to the directory on the file system where the external data source resides.
CREATE DIRECTORY emp_dir AS '/flat_files' ;
http://ecomputernotes.com
(RECORDS DELIMITED BY NEWLINE BADFILE 'bad_emp' LOGFILE 'log_emp' FIELDS TERMINATED BY ',' (empno CHAR, empname CHAR, birthdate CHAR date_format date mask "dd-mon-yyyy")) LOCATION ('emp1.txt')) PARALLEL 5 REJECT LIMIT 200; Table created.
.
http://ecomputernotes.com
emp1.txt
.
http://ecomputernotes.com
(employee_id NUMBER(6) PRIMARY KEY USING INDEX (CREATE INDEX emp_id_idx ON NEW_EMP(employee_id)), first_name VARCHAR2(20), last_name VARCHAR2(25)); Table created. SELECT INDEX_NAME, TABLE_NAME FROM USER_INDEXES WHERE TABLE_NAME = 'NEW_EMP';
http://ecomputernotes.com