Documente Academic
Documente Profesional
Documente Cultură
Thanks to Oracle:
http://download.oracle.com/otndocs/products/database/enterprise_edition/utilities/pdf/xtables_pr
eproc11g_1106.pdf
Grant succeeded.
SQL> grant read, write on directory data_dir to scott;
Grant succeeded.
Step 4 Create an external table named xtab
SQL> CONNECT scott/tiger
Connected.
SQL> CREATE TABLE xtab (COL1 varchar2(2000))
2 ORGANIZATION EXTERNAL (
3 TYPE ORACLE_LOADER
4 DEFAULT DIRECTORY data_dir
5 ACCESS PARAMETERS (
Using the Preprocessor Feature with External Tables in Oracle Database 11g Release 2
4
6 RECORDS DELIMITED BY NEWLINE
7 PREPROCESSOR execdir:'zcat'
8 FIELDS (COL1 char(2000)))
9 LOCATION ('foo.dat.gz'))
10 REJECT LIMIT UNLIMITED
11 PARALLEL 2;
Table created.
Step 5 Select from the external table to verify the data is uncompressed
SQL> SELECT * FROM xtab;
COL1
Hello World
1 row selected.
Example 2
The following example demonstrates using a shell script to uncompress the data. Shell scripts are
necessary when preprocessor programs require additional arguments. Note that /bin/zcat and
/bin/gunzip c are functionally equivalent.
Step 1 Create the preprocessor shell script
% echo /bin/gunzip c $1 > uncompress.sh
% chmod +x uncompress.sh
% cp uncompress.sh /somedirectory/bin/uncompress.sh
Note the following when creating a preprocessor shell script:
The full path name must be specified for system commands (for example, gunzip)
The data file listed in the external table LOCATION clause should be referred to by $1. (On
Windows systems, the LOCATION clause should be referred to by %1.)
On Windows systems, the first line in the .bat file must be the following:
@echo off
Otherwise, by default, Windows will echo the contents of the batch file (which will be treated
as input by the external table access driver).
Using the Preprocessor Feature with External Tables in Oracle Database 11g Release 2
5
Make sure the preprocessor shell script has EXECUTE permissions
Steps 2 and 3 remain the same as in Example 1.
Step 4 Create an external table named xtab
External Table:
An External Table is basically a file that resides on the server side, as a regular flat
file or as a data pump formatted file. The External Table is not a table itself; it is an
external file with an Oracle format and its physical location. This feature first
appeared back in Oracle 9i Release 1 and it was intended as a way of enhancing the
ETL process by reading an external flat file as if it was a regular Oracle table. On its
initial release it was only possible to create read-only External Tables, but, starting
with 10git is possible to unload data to External Tables too.
-- Simple Insert
INSERT INTO xx_reports_access_rmg
(user_name, poo_org_id, project_owning_org, hcc_org_id,
home_cost_center_org)
(SELECT user_name, poo_org_id, project_owning_org, hcc_org_id,
home_cost_center_org
FROM xx_access_external_tab)
) home_cost_center_org
FROM xx_access_external_tab)
SQL*Loader
SQL*Loader is a high-speed data loading utility that loads data from external files
into tables in an Oracle database. SQL*Loader accepts input data in a variety of
formats, can perform filtering, and can load data into multiple Oracle database
tables during the same load session.
SQL*Loader provides three methods for loading data: Conventional Path Load, Direct
Path Load, and External Table Load.
External Tables
A feature has been added to external tables that allows users to preprocess input
data before it is sent to the access driver. The ability to manipulate input data with a
preprocessor program results in additional loadable data formats, which greatly
enhances the flexibility and processing power of external tables.
The types of preprocessor programs that can be used are versatile, ranging from
system commands, user-generated binaries (for example, a C program), or usersupplied shell scripts. Because the user supplies the program to preprocess the
data, it can be tailored to meet the users specific needs. This means that the
number of loadable formats is restricted only by the ability to manipulate the
original data set.
FLASHBACK command
Undo the DROP command using FLASHBACK command
Example:
CREATE TABLE xx_drop_test (ID NUMBER,attribute1 VARCHAR2(10))
SELECT *
FROM xx_drop_test
SELECT *
FROM all_objects
For my reference:
1.
Set autotrace on
2.
Set autotiming on
3.
4.
It will display elapsed time; to open the trace file write following command
5.
6.
Trace file will be diplayed; Analyze the cost and the indexes used in table
7.
To do fine tuning we use HINTS (search in google Ex: /*+ all_rows*/ etc..
8.
9.
Use hints before columns (Ex: Explain plan for select /*+all_rows*/
project_id,segment1,creation_date from pa_projects_all)
Search in web : Index Hint, Bitmap Index, Optimization (Cost based, Rule Based)etc
BEGIN
OPEN c_test -- We can open this ref cursor dynamically using any query here
FOR
SELECT project_id, NAME
FROM pa_projects_all
WHERE TRUNC(SYSDATE) BETWEEN TRUNC(start_date) AND
TRUNC(NVL(completion_date,SYSDATE))
AND project_id = 530;
FETCH c_test
INTO l_project_id, l_name;
DBMS_OUTPUT.put_line (' Project ID : ' || l_project_id);
DBMS_OUTPUT.put_line (' Project Name: ' || l_name);
OPEN c_pm -- We can open ref cursor at runtime dynamically using any query
FOR
SELECT papf.full_name
FROM pa_project_players ppp,
pa_project_role_types pprt,
per_all_people_f papf
WHERE project_id = l_project_id
AND papf.person_id = ppp.person_id
AND ppp.project_role_type = pprt.project_role_type
AND TRUNC(SYSDATE) BETWEEN TRUNC(papf.effective_start_date) AND
TRUNC(NVL(papf.effective_end_date,SYSDATE))
AND TRUNC(SYSDATE) BETWEEN TRUNC(ppp.start_date_active) AND
TRUNC(NVL(ppp.end_date_active,SYSDATE))
AND TRUNC(SYSDATE) BETWEEN TRUNC(ppp.start_date_active) AND
TRUNC(NVL(ppp.end_date_active,SYSDATE))
AND pprt.meaning LIKE 'Project Manager';
FETCH c_pm
INTO l_pm;
DBMS_OUTPUT.put_line (' Project Manager : ' || l_pm);
CLOSE c_pm;
CLOSE c_test;
END print_project;
END test_ref;